@ledgerhq/react-ui 0.7.2 → 0.7.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.
@@ -157,7 +157,7 @@ export const Base = baseStyled.button.attrs((p) => {
157
157
  &:active {
158
158
  box-shadow: 0 0 0 4px ${(p) => rgba(p.theme.colors.primary.c60, 0.4)};
159
159
  }
160
- &:focus {
160
+ &:focus, &:hover {
161
161
  box-shadow: 0 0 0 2px ${(p) => rgba(p.theme.colors.primary.c60, 0.4)};
162
162
  }
163
163
 
@@ -2,14 +2,22 @@ import React from "react";
2
2
  import { Props as StepperProps } from "../progress/Stepper";
3
3
  import { FlexBoxProps as FlexProps } from "../../layout/Flex";
4
4
  export declare type StepProps = {
5
- /**
6
- * The label of the step.
7
- */
8
- label: string;
9
5
  /**
10
6
  * A specific index, can be used to explicitely order steps.
11
7
  */
12
8
  index?: number;
9
+ /**
10
+ * Custom header for this step.
11
+ */
12
+ header?: React.ReactNode;
13
+ /**
14
+ * Custom footer for this step.
15
+ */
16
+ footer?: React.ReactNode;
17
+ /**
18
+ * The label of the step.
19
+ */
20
+ label: string;
13
21
  /**
14
22
  * Hides the step from the progress stepper.
15
23
  */
@@ -29,19 +37,34 @@ interface InnerProps {
29
37
  */
30
38
  stepsLength: number;
31
39
  }
40
+ declare type StepChild = React.ReactElement<StepProps>;
41
+ declare type SectionRenderFunc<ExtraProps> = (props: InnerProps & ExtraProps) => React.ReactNode;
42
+ declare type SectionStepRenderFunc<ExtraProps> = (args: InnerProps & ExtraProps & {
43
+ children: React.ReactNode;
44
+ }) => React.ReactNode;
32
45
  export interface Props<ExtraProps> {
33
46
  /**
34
47
  * The index of the active step.
35
48
  */
36
49
  activeIndex: number;
37
50
  /**
38
- * An optional header displayed above the stepper.
51
+ * An optional generic header displayed above the stepper.
52
+ */
53
+ header?: SectionRenderFunc<ExtraProps>;
54
+ /**
55
+ * Custom rendering function to wrap the header (only used if the `header` is defined
56
+ * on the child for the current step.)
57
+ */
58
+ renderStepHeader?: SectionStepRenderFunc<ExtraProps>;
59
+ /**
60
+ * An optional generic footer displayed below the body.
39
61
  */
40
- header?: (props: InnerProps & ExtraProps) => React.ReactNode;
62
+ footer?: SectionRenderFunc<ExtraProps>;
41
63
  /**
42
- * An optional footer displayed below the body.
64
+ * Custom rendering function to wrap the footer (only used if the `footer` is defined
65
+ * on the child for the current step.)
43
66
  */
44
- footer?: (props: InnerProps & ExtraProps) => React.ReactNode;
67
+ renderStepFooter?: SectionStepRenderFunc<ExtraProps>;
45
68
  /**
46
69
  * Extra props that are passed to the header and footer render functions.
47
70
  */
@@ -61,17 +84,53 @@ export interface Props<ExtraProps> {
61
84
  /**
62
85
  * Custom rendering function to wrap children.
63
86
  */
64
- renderChildren?: (args: {
87
+ renderChildren?: (args: InnerProps & ExtraProps & {
65
88
  children: React.ReactNode;
66
89
  }) => React.ReactNode;
67
- /**
68
90
  /**
69
91
  * A list of children representing each step of the flow.
92
+ * Each child can have a prop `stepHeader` and/or `stepFooter` that will
93
+ * associate a custom header/footer to this particular step.
94
+ * The custom header/footer can be wrapped using the prop renderStepHeader/renderStepFooter.
70
95
  */
71
- children: React.ReactElement<StepProps> | React.ReactElement<StepProps>[];
96
+ children: StepChild | StepChild[];
72
97
  }
73
- declare function FlowStepper<ExtraProps>({ activeIndex, header, footer, extraProps, extraContainerProps, extraStepperProps, extraStepperContainerProps, renderChildren, children, }: Props<ExtraProps>): JSX.Element;
98
+ declare function FlowStepper<ExtraProps>({ activeIndex, header, renderStepHeader, footer, renderStepFooter, extraProps, extraContainerProps, extraStepperProps, extraStepperContainerProps, renderChildren, children, }: Props<ExtraProps>): JSX.Element;
74
99
  declare namespace FlowStepper {
75
100
  var Step: ({ children }: StepProps) => JSX.Element;
101
+ var Indexed: typeof FlowStepperIndexed;
76
102
  }
77
103
  export default FlowStepper;
104
+ export declare type IndexedStepProps = StepProps & {
105
+ /**
106
+ * String to identify the step. Must be different from sibling steps's `key` prop.
107
+ */
108
+ itemKey: string;
109
+ };
110
+ declare type IndexedStepperChild = React.ReactElement<IndexedStepProps>;
111
+ export declare type IndexedProps<ExtraProps> = Omit<Props<ExtraProps>, "activeIndex" | "children"> & {
112
+ /**
113
+ * The key of the active step
114
+ */
115
+ activeKey: string;
116
+ /**
117
+ * A list of children representing each step of the flow.
118
+ */
119
+ children: IndexedStepperChild | IndexedStepperChild[];
120
+ };
121
+ /**
122
+ * This is a FlowStepper where each child must have an `itemKey: string` prop
123
+ * and the active step is defined by the `activeKey: string` prop.
124
+ *
125
+ * This allows for usages with a lot of steps where dealing with indices could be
126
+ * painful and error prone (for instance inserting/removing a step somewhere would shift
127
+ * the indices of the following steps and navigation would be impacted).
128
+ *
129
+ * By using string identifiers (`itemKey`) for each step, it's more "human readable"
130
+ * and less error prone to setup a navigation logic between steps.
131
+ */
132
+ declare function FlowStepperIndexed<ExtraProps>(props: IndexedProps<ExtraProps>): JSX.Element;
133
+ declare namespace FlowStepperIndexed {
134
+ var Step: typeof IndexedStep;
135
+ }
136
+ declare function IndexedStep({ children }: IndexedStepProps): JSX.Element;
@@ -1,35 +1,84 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import React from "react";
2
13
  import { isElement } from "react-is";
3
14
  import Flex from "../../layout/Flex";
4
15
  import { Stepper } from "..";
5
- function FlowStepper({ activeIndex, header, footer, extraProps, extraContainerProps, extraStepperProps, extraStepperContainerProps, renderChildren, children, }) {
6
- const { steps, innerContents } = React.Children.toArray(children).reduce((acc, child, idx) => {
16
+ function FlowStepper({ activeIndex, header, renderStepHeader, footer, renderStepFooter, extraProps, extraContainerProps, extraStepperProps, extraStepperContainerProps, renderChildren, children, }) {
17
+ const { steps, innerContents, stepFooter, stepHeader } = React.Children.toArray(children).reduce((acc, child, idx) => {
7
18
  var _a;
8
19
  const index = (_a = (isElement(child) && child.props.index)) !== null && _a !== void 0 ? _a : idx;
9
20
  const label = isElement(child) && child.props.label;
10
21
  const hidden = isElement(child) && child.props.hidden;
22
+ const stepHeader = isElement(child) && child.props.header;
23
+ const stepFooter = isElement(child) && child.props.footer;
11
24
  if (label && !hidden) {
12
25
  acc.steps[index] = label;
13
26
  }
14
27
  if (index === activeIndex) {
15
28
  acc.innerContents = child;
29
+ acc.stepFooter = stepFooter;
30
+ acc.stepHeader = stepHeader;
16
31
  }
17
32
  return acc;
18
33
  }, {
19
34
  steps: [],
20
35
  innerContents: null,
36
+ stepHeader: null,
37
+ stepFooter: null,
21
38
  });
39
+ const renderArgs = Object.assign(Object.assign({}, extraProps), { activeIndex, stepsLength: steps.length });
40
+ function getSectionContents(renderFunc, stepSection, renderStepFunc) {
41
+ return stepSection
42
+ ? renderStepFunc
43
+ ? renderStepFunc(Object.assign(Object.assign({}, renderArgs), { children: stepSection }))
44
+ : stepSection
45
+ : renderFunc && renderFunc(renderArgs);
46
+ }
22
47
  return (React.createElement(Flex, Object.assign({ flex: 1, flexDirection: "column" }, extraContainerProps),
23
- header &&
24
- header(Object.assign(Object.assign({}, extraProps), { activeIndex, stepsLength: steps.length })),
48
+ getSectionContents(header, stepHeader, renderStepHeader),
25
49
  React.createElement(Flex, Object.assign({ my: 8, justifyContent: "center" }, extraStepperContainerProps),
26
50
  React.createElement(Stepper, Object.assign({ activeIndex: activeIndex, steps: steps, flex: 1 }, extraStepperProps))),
27
- React.createElement(Flex, { flex: 1, flexDirection: "column", position: "relative" }, renderChildren ? renderChildren({ children: innerContents }) : innerContents),
28
- footer &&
29
- footer(Object.assign(Object.assign({}, extraProps), { activeIndex, stepsLength: steps.length }))));
51
+ React.createElement(Flex, { flex: 1, flexDirection: "column", position: "relative" }, renderChildren
52
+ ? renderChildren(Object.assign(Object.assign({}, renderArgs), { children: innerContents }))
53
+ : innerContents),
54
+ getSectionContents(footer, stepFooter, renderStepFooter)));
30
55
  }
31
56
  function Step({ children }) {
32
57
  return React.createElement(React.Fragment, null, children);
33
58
  }
34
59
  FlowStepper.Step = Step;
35
60
  export default FlowStepper;
61
+ /**
62
+ * This is a FlowStepper where each child must have an `itemKey: string` prop
63
+ * and the active step is defined by the `activeKey: string` prop.
64
+ *
65
+ * This allows for usages with a lot of steps where dealing with indices could be
66
+ * painful and error prone (for instance inserting/removing a step somewhere would shift
67
+ * the indices of the following steps and navigation would be impacted).
68
+ *
69
+ * By using string identifiers (`itemKey`) for each step, it's more "human readable"
70
+ * and less error prone to setup a navigation logic between steps.
71
+ */
72
+ function FlowStepperIndexed(props) {
73
+ const { activeKey, children } = props, otherProps = __rest(props, ["activeKey", "children"]);
74
+ const activeIndex = React.Children.toArray(children).findIndex((child) => {
75
+ const res = isElement(child) && child.props.itemKey === activeKey;
76
+ return res;
77
+ });
78
+ return (React.createElement(FlowStepper, Object.assign({}, otherProps, { activeIndex: activeIndex }), children));
79
+ }
80
+ function IndexedStep({ children }) {
81
+ return React.createElement(React.Fragment, null, children);
82
+ }
83
+ FlowStepperIndexed.Step = IndexedStep;
84
+ FlowStepper.Indexed = FlowStepperIndexed;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ledgerhq/react-ui",
3
3
  "description": "Ledger Live - Desktop UI",
4
- "version": "0.7.2",
4
+ "version": "0.7.3",
5
5
  "author": "Ledger Live Team <team-live@ledger.fr>",
6
6
  "repository": "https://github.com/LedgerHQ/ui",
7
7
  "license": "MIT",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "@floating-ui/react-dom": "^0.4.0",
31
- "@ledgerhq/icons-ui": "^0.2.2",
31
+ "@ledgerhq/icons-ui": "^0.2.3",
32
32
  "@ledgerhq/ui-shared": "^0.1.5",
33
33
  "@tippyjs/react": "^4.2.6",
34
34
  "@types/color": "^3.0.2",