@bonprix-ds/react-step-navi 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { default as default_2 } from 'react';
2
1
  import { FC } from 'react';
2
+ import { ReactElement } from 'react';
3
3
 
4
4
  declare interface Props {
5
5
  /** The name of the step. */
@@ -8,12 +8,20 @@ declare interface Props {
8
8
  href?: string;
9
9
  }
10
10
 
11
+ declare interface PropsInternal extends Props {
12
+ active?: boolean;
13
+ completed?: boolean;
14
+ disabled?: boolean;
15
+ }
16
+
17
+ declare type StepElement = ReactElement<PropsInternal, typeof StepNaviStep>;
18
+
11
19
  declare const StepNavi: FC<StepNaviProps> & Subcomponents;
12
20
  export default StepNavi;
13
21
 
14
22
  export declare interface StepNaviProps {
15
23
  /** StepNavi.Step subcomponents should be placed here. */
16
- children: default_2.ReactNode;
24
+ children: StepElement | StepElement[];
17
25
  /** Amount of completed steps. */
18
26
  completedSteps?: number;
19
27
  /** Currently active step. Not index based, so starts with 1. */
package/dist/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  "use client";
2
- import { useSubcomponent as e } from "@bonprix-ds/utils";
3
- import t, { Children as n } from "react";
4
- import r from "@bonprix-ds/react-icon";
5
- import { tv as i } from "tailwind-variants";
6
- import { jsx as a, jsxs as o } from "react/jsx-runtime";
2
+ import { Children as e, cloneElement as t } from "react";
3
+ import n from "@bonprix-ds/react-icon";
4
+ import { tv as r } from "tailwind-variants";
5
+ import { jsx as i, jsxs as a } from "react/jsx-runtime";
7
6
  //#region src/StepNaviStep.tsx
8
- var s = i({
7
+ var o = r({
9
8
  slots: {
10
9
  container: "preflight w-full flex flex-col gap-1.5 items-center l:items-start xl:items-start group focus:outline-none",
11
10
  icon: "h-5 w-5 fill-clr-fg-success invisible",
@@ -20,58 +19,58 @@ var s = i({
20
19
  false: { bar: "group-hover:bg-clr-primary" }
21
20
  }
22
21
  }
23
- }), c = ({ children: e, href: t, active: n, completed: i, disabled: c }) => {
24
- let { container: l, icon: u, bar: d, labelSlot: f } = s({
25
- active: n,
26
- completed: i,
22
+ }), s = ({ children: e, href: t, active: r, completed: s, disabled: c }) => {
23
+ let { container: l, icon: u, bar: d, labelSlot: f } = o({
24
+ active: r,
25
+ completed: s,
27
26
  disabled: c
28
27
  });
29
- return /* @__PURE__ */ o("a", {
28
+ return /* @__PURE__ */ a("a", {
30
29
  href: c ? void 0 : t,
31
30
  className: l(),
32
- "aria-current": n ? "step" : "false",
31
+ "aria-current": r ? "step" : "false",
33
32
  "aria-disabled": c ? "true" : "false",
34
- "data-bpds-completed": i,
33
+ "data-bpds-completed": s,
35
34
  children: [
36
- /* @__PURE__ */ a(r, {
35
+ /* @__PURE__ */ i(n, {
37
36
  variant: "check-bold",
38
37
  className: u()
39
38
  }),
40
- /* @__PURE__ */ a("div", { className: d() }),
41
- /* @__PURE__ */ o("div", {
39
+ /* @__PURE__ */ i("div", { className: d() }),
40
+ /* @__PURE__ */ a("div", {
42
41
  className: f(),
43
- children: [e, i && /* @__PURE__ */ a("span", {
42
+ children: [e, s && /* @__PURE__ */ i("span", {
44
43
  className: "sr-only",
45
44
  children: " erfüllter schritt"
46
45
  })]
47
46
  })
48
47
  ]
49
48
  });
50
- }, l = (e, t, n) => e > n + 1 ? (console.error("activeStep must not be greater than completedSteps + 1"), n + 1) : e > t ? (console.error("activeStep must not be greater than the amount of steps. activeStep is set to last available step"), t) : e, u = ({ completedSteps: r = 0, activeStep: i = r + 1, children: o, ariaLabel: s }) => {
51
- let u = l(i, t.Children.count(o), r), { getSingleChildFromSubcomponent: d, printBadConstructionMessage: f } = e(o);
52
- return o ? /* @__PURE__ */ a("nav", {
53
- "aria-label": s,
49
+ }, c = (e, t, n) => e > n + 1 ? (console.error("activeStep must not be greater than completedSteps + 1"), n + 1) : e > t ? (console.error("activeStep must not be greater than the amount of steps. activeStep is set to last available step"), t) : e, l = ({ completedSteps: n = 0, activeStep: r = n + 1, children: a, ariaLabel: o }) => {
50
+ let s = e.toArray(a), l = c(r, s.length, n);
51
+ return /* @__PURE__ */ i("nav", {
52
+ "aria-label": o,
54
53
  "data-bpds": "step-navi",
55
- "data-bpds-completed-steps": r,
56
- "data-bpds-active-step": u,
57
- children: /* @__PURE__ */ a("ol", {
58
- className: "preflight list-none m-0 p-0 flex flex-row gap-1",
59
- children: n.map(o, (e, t) => {
60
- let n = t + 1, i = {
61
- active: u === n,
62
- completed: r >= n,
63
- disabled: n > r + 1
64
- };
65
- return /* @__PURE__ */ a("li", {
54
+ "data-bpds-completed-steps": n,
55
+ "data-bpds-active-step": l,
56
+ children: /* @__PURE__ */ i("ol", {
57
+ className: "preflight m-0 flex list-none flex-row gap-1 p-0",
58
+ children: s.map((e, r) => {
59
+ let a = r + 1;
60
+ return /* @__PURE__ */ i("li", {
66
61
  className: "flex-1",
67
- children: d(c, e, i)
68
- }, n);
62
+ children: t(e, {
63
+ active: l === a,
64
+ completed: n >= a,
65
+ disabled: a > n + 1
66
+ })
67
+ }, e.key ?? a);
69
68
  })
70
69
  })
71
- }) : (f("StepNavi"), null);
70
+ });
72
71
  };
73
- u.displayName = "StepNavi", u.Step = c, u.Step.displayName = "StepNavi.Step";
72
+ l.displayName = "StepNavi", l.Step = s, l.Step.displayName = "StepNavi.Step";
74
73
  //#endregion
75
- export { u as default };
74
+ export { l as default };
76
75
 
77
76
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/StepNaviStep.tsx","../src/StepNavi.tsx"],"sourcesContent":["// inspired by https://a11y-guidelines.orange.com/en/articles/disable-elements/#disable-a-link\nimport Icon from \"@bonprix-ds/react-icon\";\nimport React, { FC } from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nconst generateClasses = tv({\n slots: {\n container: \"preflight w-full flex flex-col gap-1.5 items-center l:items-start xl:items-start group focus:outline-none\",\n icon: \"h-5 w-5 fill-clr-fg-success invisible\",\n bar: \"w-full h-1 bg-clr-bg-disabled\",\n labelSlot: [\n \"typography-input-helper-text text-center text-clr-primary l:text-left xl:text-left px-1 break-all\",\n \"border border-transparent rounded-sm group-focus:border-clr-primary\",\n ],\n },\n variants: {\n active: {\n true: {\n bar: \"bg-clr-primary\",\n },\n },\n completed: {\n true: { icon: \"visible\" },\n },\n disabled: {\n true: {\n labelSlot: \"text-clr-disabled\",\n },\n false: {\n bar: \"group-hover:bg-clr-primary\",\n },\n },\n },\n});\n\nexport interface PropsInternal extends Props {\n active?: boolean;\n completed?: boolean;\n disabled?: boolean;\n}\n\ninterface Props {\n /** The name of the step. */\n children: string;\n /** The href attribute for the step link. */\n href?: string;\n}\n\nconst StepNaviStep: FC<Props> = ({ children, href, active, completed, disabled }: PropsInternal) => {\n const { container, icon, bar, labelSlot } = generateClasses({ active, completed, disabled });\n return (\n <a\n href={disabled ? undefined : href}\n className={container()}\n aria-current={active ? \"step\" : \"false\"}\n aria-disabled={disabled ? \"true\" : \"false\"}\n data-bpds-completed={completed}\n >\n <Icon variant=\"check-bold\" className={icon()} />\n <div className={bar()}></div>\n <div className={labelSlot()}>\n {children}\n {completed && <span className=\"sr-only\"> erfüllter schritt</span>}\n </div>\n </a>\n );\n};\n\nexport default StepNaviStep;\n","\"use client\";\n\n// inspired by https://www.w3schools.com/css/css_navbar.asp\nimport { useSubcomponent } from \"@bonprix-ds/utils\";\nimport React, { Children, FC } from \"react\";\n\nimport StepNaviStep, { PropsInternal as SubcomponentProps } from \"./StepNaviStep\";\n\ninterface Subcomponents {\n Step: typeof StepNaviStep;\n}\n\nexport interface Props {\n /** StepNavi.Step subcomponents should be placed here. */\n children: React.ReactNode;\n /** Amount of completed steps. */\n completedSteps?: number;\n /** Currently active step. Not index based, so starts with 1. */\n activeStep?: number;\n /** Accessible label for the navigation. */\n ariaLabel?: string;\n}\n\nconst checkActiveStep = (activeStep: number, stepsQuantity: number, completedSteps: number) => {\n if (activeStep > completedSteps + 1) {\n console.error(\"activeStep must not be greater than completedSteps + 1\");\n return completedSteps + 1;\n }\n if (activeStep > stepsQuantity) {\n console.error(\"activeStep must not be greater than the amount of steps. activeStep is set to last available step\");\n return stepsQuantity;\n }\n return activeStep;\n};\n\nconst StepNavi: FC<Props> & Subcomponents = ({ completedSteps = 0, activeStep = completedSteps + 1, children, ariaLabel }) => {\n const numberOfSteps = React.Children.count(children);\n const checkedActiveStep = checkActiveStep(activeStep, numberOfSteps, completedSteps);\n const { getSingleChildFromSubcomponent, printBadConstructionMessage } = useSubcomponent(children);\n\n if (!children) {\n printBadConstructionMessage(\"StepNavi\");\n return null;\n }\n\n return (\n <nav aria-label={ariaLabel} data-bpds=\"step-navi\" data-bpds-completed-steps={completedSteps} data-bpds-active-step={checkedActiveStep}>\n <ol className=\"preflight list-none m-0 p-0 flex flex-row gap-1\">\n {Children.map(children, (child, index) => {\n const stepNum = index + 1;\n const active = checkedActiveStep === stepNum;\n const completed = completedSteps >= stepNum;\n const disabled = stepNum > completedSteps + 1;\n const injectedProps = { active, completed, disabled } as SubcomponentProps;\n\n return (\n <li className=\"flex-1\" key={stepNum}>\n {getSingleChildFromSubcomponent(StepNaviStep, child, injectedProps)}\n </li>\n );\n })}\n </ol>\n </nav>\n );\n};\n\nStepNavi.displayName = \"StepNavi\";\n\nStepNavi.Step = StepNaviStep;\n// TODO: Remove once migrated away from `useSubcomponent` pattern.\nStepNavi.Step.displayName = \"StepNavi.Step\";\n\nexport default StepNavi;\n"],"mappings":";;;;;;;AAKA,IAAM,IAAkB,EAAG;CACzB,OAAO;EACL,WAAW;EACX,MAAM;EACN,KAAK;EACL,WAAW,CACT,qGACA,qEACF;CACF;CACA,UAAU;EACR,QAAQ,EACN,MAAM,EACJ,KAAK,iBACP,EACF;EACA,WAAW,EACT,MAAM,EAAE,MAAM,UAAU,EAC1B;EACA,UAAU;GACR,MAAM,EACJ,WAAW,oBACb;GACA,OAAO,EACL,KAAK,6BACP;EACF;CACF;AAC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B,CAExB;GAER,CAAC;EACC,CAAA;CACD,CAAA,KArBL,EAA4B,UAAU,GAC/B;AAsBX;AAEA,EAAS,cAAc,YAEvB,EAAS,OAAO,GAEhB,EAAS,KAAK,cAAc"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/StepNaviStep.tsx","../src/StepNavi.tsx"],"sourcesContent":["// inspired by https://a11y-guidelines.orange.com/en/articles/disable-elements/#disable-a-link\nimport Icon from \"@bonprix-ds/react-icon\";\nimport React, { FC } from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nconst generateClasses = tv({\n slots: {\n container: \"preflight w-full flex flex-col gap-1.5 items-center l:items-start xl:items-start group focus:outline-none\",\n icon: \"h-5 w-5 fill-clr-fg-success invisible\",\n bar: \"w-full h-1 bg-clr-bg-disabled\",\n labelSlot: [\n \"typography-input-helper-text text-center text-clr-primary l:text-left xl:text-left px-1 break-all\",\n \"border border-transparent rounded-sm group-focus:border-clr-primary\",\n ],\n },\n variants: {\n active: {\n true: {\n bar: \"bg-clr-primary\",\n },\n },\n completed: {\n true: { icon: \"visible\" },\n },\n disabled: {\n true: {\n labelSlot: \"text-clr-disabled\",\n },\n false: {\n bar: \"group-hover:bg-clr-primary\",\n },\n },\n },\n});\n\nexport interface PropsInternal extends Props {\n active?: boolean;\n completed?: boolean;\n disabled?: boolean;\n}\n\ninterface Props {\n /** The name of the step. */\n children: string;\n /** The href attribute for the step link. */\n href?: string;\n}\n\nconst StepNaviStep: FC<Props> = ({ children, href, active, completed, disabled }: PropsInternal) => {\n const { container, icon, bar, labelSlot } = generateClasses({ active, completed, disabled });\n return (\n <a\n href={disabled ? undefined : href}\n className={container()}\n aria-current={active ? \"step\" : \"false\"}\n aria-disabled={disabled ? \"true\" : \"false\"}\n data-bpds-completed={completed}\n >\n <Icon variant=\"check-bold\" className={icon()} />\n <div className={bar()}></div>\n <div className={labelSlot()}>\n {children}\n {completed && <span className=\"sr-only\"> erfüllter schritt</span>}\n </div>\n </a>\n );\n};\n\nexport default StepNaviStep;\n","\"use client\";\n\nimport React, { Children, cloneElement, FC, ReactElement } from \"react\";\n\nimport StepNaviStep, { PropsInternal as StepNaviStepInternalProps } from \"./StepNaviStep\";\n\ninterface Subcomponents {\n Step: typeof StepNaviStep;\n}\n\ntype StepElement = ReactElement<StepNaviStepInternalProps, typeof StepNaviStep>;\n\nexport interface Props {\n /** StepNavi.Step subcomponents should be placed here. */\n children: StepElement | StepElement[];\n /** Amount of completed steps. */\n completedSteps?: number;\n /** Currently active step. Not index based, so starts with 1. */\n activeStep?: number;\n /** Accessible label for the navigation. */\n ariaLabel?: string;\n}\n\nconst checkActiveStep = (activeStep: number, stepsQuantity: number, completedSteps: number) => {\n if (activeStep > completedSteps + 1) {\n console.error(\"activeStep must not be greater than completedSteps + 1\");\n return completedSteps + 1;\n }\n\n if (activeStep > stepsQuantity) {\n console.error(\"activeStep must not be greater than the amount of steps. activeStep is set to last available step\");\n return stepsQuantity;\n }\n\n return activeStep;\n};\n\nconst StepNavi: FC<Props> & Subcomponents = ({ completedSteps = 0, activeStep = completedSteps + 1, children, ariaLabel }) => {\n const steps = Children.toArray(children) as StepElement[];\n const checkedActiveStep = checkActiveStep(activeStep, steps.length, completedSteps);\n\n return (\n <nav aria-label={ariaLabel} data-bpds=\"step-navi\" data-bpds-completed-steps={completedSteps} data-bpds-active-step={checkedActiveStep}>\n <ol className=\"preflight m-0 flex list-none flex-row gap-1 p-0\">\n {steps.map((step, index) => {\n const stepNumber = index + 1;\n\n return (\n <li className=\"flex-1\" key={step.key ?? stepNumber}>\n {cloneElement(step, {\n active: checkedActiveStep === stepNumber,\n completed: completedSteps >= stepNumber,\n disabled: stepNumber > completedSteps + 1,\n })}\n </li>\n );\n })}\n </ol>\n </nav>\n );\n};\n\nStepNavi.displayName = \"StepNavi\";\n\nStepNavi.Step = StepNaviStep;\nStepNavi.Step.displayName = \"StepNavi.Step\";\n\nexport default StepNavi;\n"],"mappings":";;;;;;AAKA,IAAM,IAAkB,EAAG;CACz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AM,KAAK,GAAM,MAAU;IAC1B,IAAM,IAAa,IAAQ;IAE3B,OACE,kBAAC,MAAD;KAAI,WAAU;KACX,UAAA,EAAa,GAAM;MAClB,QAAQ,MAAsB;MAC9B,WAAW,KAAkB;MAC7B,UAAU,IAAa,IAAiB;KAC1C,CAAC;IACC,GANwB,EAAK,OAAO,CAMpC;GAER,CAAC;EACC,CAAA;CACD,CAAA;AAET;AAEA,EAAS,cAAc,YAEvB,EAAS,OAAO,GAChB,EAAS,KAAK,cAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonprix-ds/react-step-navi",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "StepNavi component, implemented in React, for the Bonprix Design System.",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -29,8 +29,8 @@
29
29
  "directory": "packages/react/step-navi"
30
30
  },
31
31
  "dependencies": {
32
- "@bonprix-ds/react-icon": "1.1.1",
33
- "@bonprix-ds/utils": "0.1.2"
32
+ "@bonprix-ds/react-icon": "1.1.2",
33
+ "@bonprix-ds/utils": "0.2.0"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": "^19.0.0",
@@ -38,7 +38,7 @@
38
38
  "tailwind-variants": "0.3.1"
39
39
  },
40
40
  "devDependencies": {
41
- "vite": "8.2.0",
41
+ "vite": "8.2.1",
42
42
  "@types/react": "19.2.18",
43
43
  "@vitejs/plugin-react": "6.0.5",
44
44
  "rollup-preserve-directives": "1.1.3",