diff --git a/src/plugins/counter/Counter.tsx b/src/plugins/counter/Counter.tsx index 7450513..c34d5ff 100644 --- a/src/plugins/counter/Counter.tsx +++ b/src/plugins/counter/Counter.tsx @@ -10,20 +10,34 @@ import { PluginProps, useLightboxState, } from "../../index.js"; +import { resolveCounterProps } from "./props.js"; -export function CounterComponent({ counter: { className, ...rest } = {} }: ComponentProps) { +export function CounterComponent({ counter }: ComponentProps) { const { slides, currentIndex } = useLightboxState(); + const { + separator, + container: { className, ...rest }, + // TODO v4: remove legacy configuration options + className: legacyClassName, + ...legacyRest + } = resolveCounterProps(counter); + if (slides.length === 0) return null; return ( -
- {currentIndex + 1} / {slides.length} +
+ {currentIndex + 1} {separator} {slides.length}
); } /** Counter plugin */ -export function Counter({ addChild }: PluginProps) { +export function Counter({ augment, addChild }: PluginProps) { + augment(({ counter, ...restProps }) => ({ + counter: resolveCounterProps(counter), + ...restProps, + })); + addChild(MODULE_CONTROLLER, createModule(PLUGIN_COUNTER, CounterComponent)); } diff --git a/src/plugins/counter/index.ts b/src/plugins/counter/index.ts index 6319b39..6d20516 100644 --- a/src/plugins/counter/index.ts +++ b/src/plugins/counter/index.ts @@ -4,8 +4,14 @@ import { Counter } from "./Counter.js"; declare module "../../types.js" { interface LightboxProps { - /** HTML div element attributes to be passed to the Counter plugin container */ - counter?: React.HTMLAttributes; + // TODO v4: remove html attributes from `counter` prop + /** Counter plugin settings */ + counter?: React.HTMLAttributes & { + /** custom separator */ + separator?: string; + /** counter container HTML attributes */ + container?: React.HTMLAttributes; + }; } } diff --git a/src/plugins/counter/props.ts b/src/plugins/counter/props.ts new file mode 100644 index 0000000..84cf362 --- /dev/null +++ b/src/plugins/counter/props.ts @@ -0,0 +1,11 @@ +import { LightboxProps } from "../../index.js"; + +export const defaultCounterProps = { + separator: "/", + container: {}, +} as Required>; + +export const resolveCounterProps = (counter: LightboxProps["counter"]) => ({ + ...defaultCounterProps, + ...counter, +});