@ledgerhq/react-ui 0.2.0 → 0.5.0

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.
Files changed (135) hide show
  1. package/README.md +47 -4
  2. package/assets/logos/LedgerLiveAltRegular.d.ts +0 -1
  3. package/assets/logos/LedgerLiveRegular.d.ts +0 -1
  4. package/components/Chart/index.d.ts +0 -1
  5. package/components/Chart/index.js +1 -1
  6. package/components/Table/Columns.d.ts +62 -13
  7. package/components/Table/Columns.js +8 -18
  8. package/components/Table/index.d.ts +47 -14
  9. package/components/Table/index.js +37 -20
  10. package/components/Table/stories.helper.js +19 -18
  11. package/components/Tag/index.d.ts +18 -5
  12. package/components/Tag/index.js +54 -21
  13. package/components/animations/GlitchText/index.d.ts +6 -0
  14. package/components/animations/GlitchText/index.js +35 -0
  15. package/components/asorted/Divider/index.d.ts +0 -1
  16. package/components/asorted/Divider/index.js +2 -2
  17. package/components/asorted/Icon/BoxedIcon.d.ts +48 -0
  18. package/components/asorted/Icon/BoxedIcon.js +58 -0
  19. package/components/asorted/Icon/Icon.d.ts +0 -1
  20. package/components/asorted/Icon/index.d.ts +2 -0
  21. package/components/asorted/Icon/index.js +2 -0
  22. package/components/asorted/Text/index.d.ts +6 -22
  23. package/components/asorted/Text/index.js +7 -16
  24. package/components/asorted/Text/styles.d.ts +2 -1
  25. package/components/asorted/Text/styles.js +21 -9
  26. package/components/asorted/index.d.ts +1 -1
  27. package/components/asorted/index.js +1 -1
  28. package/components/cards/Carousel/Slide.js +3 -3
  29. package/components/cards/Carousel/index.js +8 -8
  30. package/components/cta/Button/index.d.ts +16 -8
  31. package/components/cta/Button/index.js +76 -65
  32. package/components/cta/Link/index.d.ts +59 -2
  33. package/components/cta/Link/index.js +17 -12
  34. package/components/cta/Toggle/index.d.ts +0 -1
  35. package/components/cta/Toggle/index.js +1 -1
  36. package/components/form/BaseInput/index.d.ts +81 -11
  37. package/components/form/BaseInput/index.js +42 -19
  38. package/components/form/Checkbox/Checkbox.js +12 -9
  39. package/components/form/Dropdown/index.d.ts +0 -1
  40. package/components/form/Dropdown/index.js +2 -2
  41. package/components/form/LegendInput/index.d.ts +26 -2
  42. package/components/form/LegendInput/index.js +5 -4
  43. package/components/form/NumberInput/index.d.ts +25 -3
  44. package/components/form/NumberInput/index.js +19 -7
  45. package/components/form/QrCodeInput/index.d.ts +25 -3
  46. package/components/form/QrCodeInput/index.js +7 -6
  47. package/components/form/QuantityInput/index.d.ts +26 -4
  48. package/components/form/QuantityInput/index.js +9 -8
  49. package/components/form/Radio/RadioElement.d.ts +5 -2
  50. package/components/form/Radio/RadioElement.js +15 -13
  51. package/components/form/Radio/RadioListElement.d.ts +22 -0
  52. package/components/form/Radio/RadioListElement.js +63 -0
  53. package/components/form/Radio/index.d.ts +8 -1
  54. package/components/form/Radio/index.js +2 -0
  55. package/components/form/SearchInput/index.d.ts +24 -2
  56. package/components/form/SearchInput/index.js +4 -3
  57. package/components/form/SelectInput/Control.d.ts +2 -2
  58. package/components/form/SelectInput/Control.js +3 -7
  59. package/components/form/SelectInput/DropdownIndicator.d.ts +0 -1
  60. package/components/form/SelectInput/DropdownIndicator.js +1 -1
  61. package/components/form/SelectInput/IndicatorsContainer.d.ts +0 -1
  62. package/components/form/SelectInput/MenuList.d.ts +0 -1
  63. package/components/form/SelectInput/MenuList.js +1 -1
  64. package/components/form/SelectInput/Option.js +11 -11
  65. package/components/form/SelectInput/ValueContainer.js +1 -1
  66. package/components/form/SelectInput/index.d.ts +3 -2
  67. package/components/form/SelectInput/index.js +5 -5
  68. package/components/form/SplitInput/index.js +5 -5
  69. package/components/form/Switch/Switch.js +8 -8
  70. package/components/helpers.d.ts +2 -2
  71. package/components/layout/Box/index.d.ts +8 -0
  72. package/components/layout/Box/index.js +3 -0
  73. package/components/layout/Drawer/index.d.ts +13 -0
  74. package/components/layout/{Side/Side.js → Drawer/index.js} +12 -12
  75. package/components/layout/Flex/index.d.ts +7 -7
  76. package/components/layout/Flex/index.js +2 -11
  77. package/components/layout/Grid/index.d.ts +3 -2
  78. package/components/layout/Grid/index.js +3 -6
  79. package/components/layout/Popin/index.d.ts +27 -6
  80. package/components/layout/Popin/index.js +65 -41
  81. package/components/layout/Side/index.d.ts +0 -1
  82. package/components/layout/Side/index.js +2 -2
  83. package/components/layout/index.d.ts +2 -0
  84. package/components/layout/index.js +2 -0
  85. package/components/loaders/ProgressLoader/index.d.ts +0 -1
  86. package/components/loaders/ProgressLoader/index.js +3 -3
  87. package/components/message/Alert/index.d.ts +22 -3
  88. package/components/message/Alert/index.js +31 -23
  89. package/components/message/Log/index.js +1 -1
  90. package/components/message/Notification/Badge.js +2 -2
  91. package/components/message/Notification/index.js +4 -6
  92. package/components/message/StatusNotification/index.d.ts +11 -0
  93. package/components/message/StatusNotification/index.js +33 -0
  94. package/components/message/Tip/index.d.ts +7 -0
  95. package/components/message/Tip/index.js +43 -0
  96. package/components/message/Tooltip/index.d.ts +3 -3
  97. package/components/message/Tooltip/index.js +1 -1
  98. package/components/message/Tooltip/styles.js +3 -3
  99. package/components/message/index.d.ts +3 -0
  100. package/components/message/index.js +3 -0
  101. package/components/navigation/Aside/index.d.ts +5 -1
  102. package/components/navigation/Breadcrumb/index.js +6 -6
  103. package/components/navigation/Header/index.d.ts +3 -3
  104. package/components/navigation/progress/ProgressBar/Onboarding.d.ts +0 -1
  105. package/components/navigation/progress/ProgressBar/Onboarding.js +6 -6
  106. package/components/navigation/progress/Stepper/index.js +9 -9
  107. package/components/navigation/sideBar/Item/Item.d.ts +4 -3
  108. package/components/navigation/sideBar/Item/Item.js +34 -16
  109. package/components/navigation/sideBar/Logo/Logo.d.ts +0 -1
  110. package/components/navigation/sideBar/SideBar/SideBar.d.ts +1 -2
  111. package/components/navigation/sideBar/SideBar/SideBar.js +14 -6
  112. package/components/navigation/sideBar/Toggle/Toggle.d.ts +0 -1
  113. package/components/navigation/sideBar/Toggle/Toggle.js +2 -2
  114. package/components/styled.d.ts +16 -0
  115. package/components/styled.js +13 -0
  116. package/components/tabs/Bar/index.js +4 -4
  117. package/components/tabs/Chip/index.d.ts +13 -0
  118. package/components/tabs/Chip/index.js +21 -0
  119. package/components/tabs/Pill/index.js +7 -7
  120. package/components/tabs/Tabs/index.js +8 -7
  121. package/components/tabs/index.d.ts +2 -0
  122. package/components/tabs/index.js +2 -0
  123. package/package.json +4 -4
  124. package/styles/InvertTheme.d.ts +1 -8
  125. package/styles/StyleProvider.d.ts +3 -3
  126. package/styles/StyleProvider.js +3 -3
  127. package/styles/global.d.ts +1 -0
  128. package/styles/global.js +15 -36
  129. package/styles/index.d.ts +0 -1
  130. package/styles/index.js +0 -1
  131. package/styles/theme.d.ts +5 -2
  132. package/styles/theme.js +7 -8
  133. package/components/layout/Side/Side.d.ts +0 -13
  134. package/styles/reset.d.ts +0 -2
  135. package/styles/reset.js +0 -62
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ## Reference
12
12
 
13
- [📚 The storybook is hosted here.](https://ledger-live-ui-react.vercel.app/)
13
+ **[🔗 Storybook](https://ledger-live-ui-react.vercel.app/)**
14
14
 
15
15
  ## Installation
16
16
 
@@ -20,7 +20,15 @@
20
20
  npm i @ledgerhq/react-ui
21
21
  ```
22
22
 
23
- _And if the React packages are not installed:_
23
+ ### Peer dependencies
24
+
25
+ This library uses [styled components](https://styled-components.com/) heavily and relies on it being installed separately (to avoid package duplication).
26
+
27
+ ```sh
28
+ npm i styled-components
29
+ ```
30
+
31
+ And (obviously) if React packages are not already installed:
24
32
 
25
33
  ```sh
26
34
  npm i react react-dom
@@ -51,7 +59,7 @@ import { Text, Flex, Logos } from "@ledgerhq/react-ui";
51
59
  function Hello() {
52
60
  return (
53
61
  <Flex flexDirection="column" alignItems="center" rowGap={12} p={12}>
54
- <Text color="palette.neutral.c100">
62
+ <Text color="neutral.c100">
55
63
  <Logos.LedgerLiveRegular />
56
64
  </Text>
57
65
  <Text variant="h1">Hello, world!</Text>
@@ -92,6 +100,41 @@ With webpack 5 the rule below will process the font files and save them in the `
92
100
  },
93
101
  ```
94
102
 
103
+ #### Scoped Imports
104
+
105
+ If you are using a loader that saves the fonts with custom names (for instance when using `create-react-app`), you can use the `fontMappings` prop to map the font names.
106
+
107
+ ```js
108
+ // These imports return the path to the public folder where the loader saves the fonts during the build.
109
+ import HMAlphaMono from "@ledgerhq/react-ui/assets/fonts/HMAlphaMono-Medium.woff2";
110
+ import InterBold from "@ledgerhq/react-ui/assets/fonts/Inter-Bold.woff2";
111
+ import InterExtraBold from "@ledgerhq/react-ui/assets/fonts/Inter-ExtraBold.woff2";
112
+ import InterExtraLight from "@ledgerhq/react-ui/assets/fonts/Inter-ExtraLight-BETA.woff2";
113
+ import InterLight from "@ledgerhq/react-ui/assets/fonts/Inter-Light-BETA.woff2";
114
+ import InterMedium from "@ledgerhq/react-ui/assets/fonts/Inter-Medium.woff2";
115
+ import InterRegular from "@ledgerhq/react-ui/assets/fonts/Inter-Regular.woff2";
116
+ import InterSemiBold from "@ledgerhq/react-ui/assets/fonts/Inter-SemiBold.woff2";
117
+
118
+ // Map the font names with the file path.
119
+ const fontMap = {
120
+ "HMAlphaMono-Medium": HMAlphaMono,
121
+ "Inter-Bold": InterBold,
122
+ "Inter-ExtraBold": InterExtraBold,
123
+ "Inter-ExtraLight-BETA": InterExtraLight,
124
+ "Inter-Light-BETA": InterLight,
125
+ "Inter-Medium": InterMedium,
126
+ "Inter-Regular": InterRegular,
127
+ "Inter-SemiBold": InterSemiBold,
128
+ };
129
+
130
+ // The substring call is used to make the path relative (removes the prepending /).
131
+ const fontMappings = (name) => fontMap[name].substring(1);
132
+
133
+ /* … */
134
+
135
+ <StyleProvider fontPath="path/to/fonts" fontMappings={fontMappings}>
136
+ ```
137
+
95
138
  #### Manually
96
139
 
97
140
  The `.woff2` font files are located in the `src/assets/fonts` folder.
@@ -129,7 +172,7 @@ function Root() {
129
172
  return (
130
173
  <StyleProvider fontsPath="assets" selectedPalette={palette}>
131
174
  <Flex flexDirection="column" alignItems="center" rowGap={12} p={12}>
132
- <Text color="palette.neutral.c100">
175
+ <Text color="neutral.c100">
133
176
  <Logos.LedgerLiveRegular />
134
177
  </Text>
135
178
  <Text variant="h1">Hello, world!</Text>
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  declare type Props = {
3
2
  width?: number | string;
4
3
  height?: number | string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  declare type Props = {
3
2
  width?: number | string;
4
3
  height?: number | string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { ChartProps } from "react-chartjs-2";
3
2
  import "chartjs-adapter-moment";
4
3
  import type { Item, timeOptions } from "./types";
@@ -72,7 +72,7 @@ const defaultValue = {
72
72
  export default (_a) => {
73
73
  var { data, color, variant = defaultValue.variant, valueKey = defaultValue.valueKey, timeOptions = defaultValue.timeOptions } = _a, chartProps = __rest(_a, ["data", "color", "variant", "valueKey", "timeOptions"]);
74
74
  const theme = useTheme();
75
- const config = useMemo(() => getConfig(variant, { gridColor: theme.colors.palette.neutral.c40, timeOptions }), [variant, theme.colors.palette.neutral.c40, timeOptions]);
75
+ const config = useMemo(() => getConfig(variant, { gridColor: theme.colors.neutral.c40, timeOptions }), [variant, theme.colors.neutral.c40, timeOptions]);
76
76
  // inject default font configuration at mount
77
77
  useEffect(() => {
78
78
  defaults.font = fontConfig;
@@ -1,34 +1,83 @@
1
1
  import React from "react";
2
2
  import { Props as IconProps } from "../asorted/Icon";
3
- import Text, { BaseTextProps } from "../asorted/Text";
3
+ import Text, { TextProps } from "../asorted/Text";
4
+ export interface Column<T> {
5
+ /**
6
+ * A function called to render each cell of the column.
7
+ */
8
+ render: (props: CellProps<T>) => React.ReactNode;
9
+ /**
10
+ * A valid grid template [value](https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns#values).
11
+ * This layout is applied to every cell of the column.
12
+ * Default to "min-content" - the largest minimal content contribution of the grid item.
13
+ */
14
+ layout?: string;
15
+ /**
16
+ * A function called to render the header cell.
17
+ * If omitted the rendered header element will be an empty div.
18
+ */
19
+ header?: () => React.ReactNode;
20
+ }
4
21
  export interface CellProps<T> {
22
+ /**
23
+ * The cell element.
24
+ */
5
25
  elt: T;
26
+ /**
27
+ * The row index.
28
+ */
6
29
  rowIndex: number;
30
+ /**
31
+ * The column index.
32
+ */
7
33
  columnIndex: number;
8
34
  }
9
- declare type HeaderFn = () => React.ReactNode;
10
- export interface Column<T> {
11
- layout?: string;
12
- render: (props: CellProps<T>) => React.ReactNode;
13
- header?: HeaderFn;
14
- }
15
35
  /**
16
36
  * A column which contains a single icon and that has a fixed width.
17
37
  */
18
- export declare function IconColumn<T>({ props, header, layout, }: {
19
- props: (elt: T) => Pick<IconProps, "name" | "weight"> & BaseTextProps;
20
- header?: HeaderFn;
38
+ declare function iconColumn<T>({ props, header, layout, }: {
39
+ /**
40
+ * An object containing the unerlying <Text /> wrapper props as well as
41
+ * the "name" and "weight" props of the unerlying <Icon />.
42
+ */
43
+ props: (elt: T) => Pick<IconProps, "name" | "weight"> & TextProps;
44
+ /**
45
+ * An optional render function to display the column header.
46
+ */
47
+ header?: () => React.ReactNode;
48
+ /**
49
+ * The grid column layout, by default "min-content".
50
+ */
21
51
  layout?: string;
22
52
  }): Column<T>;
53
+ export { iconColumn as icon };
23
54
  /**
24
55
  * A column that contains a title and a subtitle.
25
56
  */
26
- export declare function TextColumn<T>({ title, subtitle, header, layout, titleProps, subtitleProps, }: {
57
+ declare function textColumn<T>({ title, subtitle, header, layout, titleProps, subtitleProps, }: {
58
+ /**
59
+ * An optional title.
60
+ */
27
61
  title?: (elt: T) => React.ReactNode;
62
+ /**
63
+ * An optional subtitle.
64
+ */
28
65
  subtitle?: (elt: T) => React.ReactNode;
29
- header?: HeaderFn;
66
+ /**
67
+ * An optional render function to display the column header.
68
+ */
69
+ header?: () => React.ReactNode;
70
+ /**
71
+ * The grid column layout, by default "auto".
72
+ */
30
73
  layout?: string;
74
+ /**
75
+ * Optional extra props passed to the title <Text /> wrapper.
76
+ */
31
77
  titleProps?: (elt: T) => Partial<React.ComponentProps<typeof Text>>;
78
+ /**
79
+ * Optional extra props passed to the subtitle <Text /> wrapper.
80
+ */
32
81
  subtitleProps?: (elt: T) => Partial<React.ComponentProps<typeof Text>>;
33
82
  }): Column<T>;
34
- export {};
83
+ export { textColumn as text };
@@ -16,38 +16,28 @@ import Text from "../asorted/Text";
16
16
  /**
17
17
  * A column which contains a single icon and that has a fixed width.
18
18
  */
19
- export function IconColumn({ props, header, layout, }) {
19
+ function iconColumn({ props, header, layout, }) {
20
20
  return {
21
21
  layout: layout || "min-content",
22
22
  render: ({ elt }) => {
23
23
  const _a = props(elt), { name, weight } = _a, textProps = __rest(_a, ["name", "weight"]);
24
- return (React.createElement(Text, Object.assign({}, textProps, { style: { display: "flex" } }),
24
+ return (React.createElement(Text, Object.assign({}, textProps, { style: { display: "flex", alignItems: "center" } }),
25
25
  React.createElement(Icon, { name: name, weight: weight })));
26
26
  },
27
27
  header,
28
28
  };
29
29
  }
30
+ export { iconColumn as icon };
30
31
  /**
31
32
  * A column that contains a title and a subtitle.
32
33
  */
33
- export function TextColumn({
34
- // An optional title.
35
- title,
36
- // An optional subtitle.
37
- subtitle,
38
- // An optional render function to display the column header.
39
- header,
40
- // The grid column layout, by default "auto".
41
- layout,
42
- // Optional extra props passed to the title <Text /> wrapper.
43
- titleProps,
44
- // Optional extra props passed to the subtitle <Text /> wrapper.
45
- subtitleProps, }) {
34
+ function textColumn({ title, subtitle, header, layout, titleProps, subtitleProps, }) {
46
35
  return {
47
36
  layout: layout || "auto",
48
- render: ({ elt }) => (React.createElement(FlexBox, { flexDirection: "column" },
49
- title && (React.createElement(Text, Object.assign({ fontWeight: "medium", variant: "body", textOverflow: "ellipsis", overflow: "hidden", color: "palette.neutral.c100" }, ((titleProps && titleProps(elt)) || {})), title(elt))),
50
- subtitle && (React.createElement(Text, Object.assign({ fontWeight: "medium", variant: "paragraph", textOverflow: "ellipsis", overflow: "hidden", color: "palette.neutral.c80" }, ((subtitleProps && subtitleProps(elt)) || {})), subtitle(elt))))),
37
+ render: ({ elt }) => (React.createElement(FlexBox, { flexDirection: "column", justifyContent: "center" },
38
+ title && (React.createElement(Text, Object.assign({ fontWeight: "medium", variant: "body", textOverflow: "ellipsis", overflow: "hidden", color: "neutral.c100" }, ((titleProps && titleProps(elt)) || {})), title(elt))),
39
+ subtitle && (React.createElement(Text, Object.assign({ fontWeight: "medium", variant: "paragraph", textOverflow: "ellipsis", overflow: "hidden", color: "neutral.c80" }, ((subtitleProps && subtitleProps(elt)) || {})), subtitle(elt))))),
51
40
  header,
52
41
  };
53
42
  }
43
+ export { textColumn as text };
@@ -1,33 +1,66 @@
1
1
  import React from "react";
2
- import { SpaceProps, ColorProps, BorderProps, FlexboxProps, GridColumnProps } from "styled-system";
2
+ import { BorderProps, GridColumnProps } from "styled-system";
3
3
  import { Props as GridProps } from "../layout/Grid";
4
4
  import type { Column } from "./Columns";
5
+ import { BaseStyledProps } from "../styled";
5
6
  export type { Column };
6
- export interface ContainerExtraProps extends SpaceProps, ColorProps, BorderProps, FlexboxProps {
7
+ export interface ContainerExtraProps extends BorderProps, BaseStyledProps {
7
8
  }
8
9
  export interface ContainerProps extends ContainerExtraProps, GridProps {
9
10
  }
10
- export declare const Container: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, GridProps & ContainerExtraProps, never>;
11
- export declare const ExtraRowContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, GridColumnProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>>, never>;
12
- export interface Props<T> extends Omit<ContainerProps, "columns" | "color"> {
11
+ export declare const ExtraRowContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
12
+ gridColumn: string;
13
+ } & GridColumnProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>>, "gridColumn">;
14
+ export declare type RowContainerProps = {
15
+ rowIndex: number;
16
+ };
17
+ export declare const RowContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, import("styled-system").SpaceProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").FlexboxProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").PositionProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").ColorProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").LayoutProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & BorderProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>> & import("styled-system").OverflowProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & {
18
+ columnGap?: string | number | undefined;
19
+ rowGap?: string | number | undefined;
20
+ color?: string | undefined;
21
+ } & RowContainerProps, "overflow" | "p" | "color" | "size" | "rowGap" | "alignContent" | "alignItems" | "alignSelf" | "backgroundColor" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "bottom" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "opacity" | "order" | "overflowX" | "overflowY" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "top" | "verticalAlign" | "width" | "zIndex" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "margin" | "padding" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "bg" | "borderX" | "borderY">;
22
+ interface CommonProps<T> {
23
+ /** Table data */
13
24
  data: T[];
25
+ /** Columns used to render table cells and headers. */
14
26
  columns: Column<T>[];
15
- withHeaders?: boolean;
27
+ /**
28
+ * An optional rendering function that will get called after each row render.
29
+ * Can be used to display additional rows and columns dynamically.
30
+ */
16
31
  extraRender?: (elt: T, index: number) => React.ReactNode;
32
+ /**
33
+ * A render function that can be used to wrap each row of the table inside an custom element.
34
+ */
35
+ renderRow?: (rowIndex: number, children: React.ReactNode) => React.ReactNode;
17
36
  }
18
- export interface RowProps<T> {
19
- data: T[];
20
- columns: Column<T>[];
37
+ export interface Props<T> extends CommonProps<T>, Omit<ContainerProps, "columns" | "color"> {
38
+ /**
39
+ * Renders headers if set to true.
40
+ */
41
+ withHeaders?: boolean;
42
+ }
43
+ export interface RowProps<T> extends CommonProps<T> {
21
44
  render?: (args: {
22
45
  column: Column<T>;
23
46
  rowIndex: number;
24
47
  columnIndex: number;
25
48
  children: React.ReactNode;
26
49
  }) => React.ReactNode;
27
- extraRender?: (elt: T, index: number) => React.ReactNode;
28
50
  }
29
- declare function RowsComponent<T>({ data, columns, extraRender, render }: RowProps<T>): JSX.Element;
51
+ declare function RowsComponent<T>({ data, columns, render, extraRender, renderRow, }: RowProps<T>): JSX.Element;
30
52
  export declare const Rows: typeof RowsComponent;
31
- declare function Table<T>({ data, columns, withHeaders, extraRender, ...containerProps }: Props<T>): JSX.Element;
32
- declare const _default: typeof Table;
33
- export default _default;
53
+ declare function Table<T>({ data, columns, withHeaders, extraRender, renderRow, ...containerProps }: Props<T>): JSX.Element;
54
+ declare namespace Table {
55
+ var Columns: typeof import("./Columns");
56
+ var ExtraRowContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
57
+ gridColumn: string;
58
+ } & GridColumnProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>>, "gridColumn">;
59
+ var RowContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, import("styled-system").SpaceProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").FlexboxProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").PositionProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").ColorProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").LayoutProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & BorderProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>> & import("styled-system").OverflowProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & {
60
+ columnGap?: string | number | undefined;
61
+ rowGap?: string | number | undefined;
62
+ color?: string | undefined;
63
+ } & RowContainerProps, "overflow" | "p" | "color" | "size" | "rowGap" | "alignContent" | "alignItems" | "alignSelf" | "backgroundColor" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "bottom" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "opacity" | "order" | "overflowX" | "overflowY" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "top" | "verticalAlign" | "width" | "zIndex" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "margin" | "padding" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "bg" | "borderX" | "borderY">;
64
+ }
65
+ declare const memoTable: typeof Table;
66
+ export default memoTable;
@@ -11,32 +11,42 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import React, { memo, useMemo } from "react";
13
13
  import styled from "styled-components";
14
- import { space, color, border, flexbox, gridColumn, } from "styled-system";
14
+ import { border, gridColumn } from "styled-system";
15
15
  import Grid from "../layout/Grid";
16
- export const Container = styled(Grid) `
17
- ${space}
18
- ${color}
16
+ import Flex from "../layout/Flex";
17
+ import * as Columns from "./Columns";
18
+ const Container = styled(Grid) `
19
19
  ${border}
20
- ${flexbox}
21
20
  `;
22
- export const ExtraRowContainer = styled.div `
21
+ export const ExtraRowContainer = styled.div.attrs({ gridColumn: "1 / -1" }) `
23
22
  ${gridColumn}
24
23
  `;
25
- function RowsComponent({ data, columns, extraRender, render }) {
26
- return (React.createElement(React.Fragment, { key: "row-component" }, data.map((elt, rowIndex) => (React.createElement(React.Fragment, { key: `row-component-row-${rowIndex}` },
27
- columns.map((column, columnIndex) => (React.createElement(React.Fragment, { key: `row-component-column-${rowIndex}${columnIndex}` }, render
28
- ? render({
29
- column,
30
- rowIndex,
31
- columnIndex,
32
- children: column.render({ elt, rowIndex, columnIndex }),
33
- })
34
- : column.render({ elt, rowIndex, columnIndex })))),
35
- (extraRender && extraRender(elt, rowIndex)) || null)))));
24
+ export const RowContainer = styled(Flex) `
25
+ display: contents;
26
+ `;
27
+ function RowsComponent({ data, columns, render, extraRender, renderRow, }) {
28
+ return (React.createElement(React.Fragment, { key: "row-component" }, data.map((elt, rowIndex) => {
29
+ const row = (React.createElement(React.Fragment, null,
30
+ columns.map((column, columnIndex) => (React.createElement(React.Fragment, { key: `row-component-column-${rowIndex}${columnIndex}` }, render
31
+ ? render({
32
+ column,
33
+ rowIndex,
34
+ columnIndex,
35
+ children: column.render({ elt, rowIndex, columnIndex }),
36
+ })
37
+ : column.render({ elt, rowIndex, columnIndex })))),
38
+ (extraRender && extraRender(elt, rowIndex)) || null));
39
+ if (renderRow) {
40
+ return renderRow(rowIndex, row);
41
+ }
42
+ else {
43
+ return React.createElement(React.Fragment, { key: `row-component-row-${rowIndex}` }, row);
44
+ }
45
+ })));
36
46
  }
37
47
  export const Rows = memo(RowsComponent);
38
48
  function Table(_a) {
39
- var { data, columns, withHeaders, extraRender } = _a, containerProps = __rest(_a, ["data", "columns", "withHeaders", "extraRender"]);
49
+ var { data, columns, withHeaders, extraRender, renderRow } = _a, containerProps = __rest(_a, ["data", "columns", "withHeaders", "extraRender", "renderRow"]);
40
50
  const gridTemplateColumns = useMemo(() => columns.reduce((acc, col) => `${acc} ${col.layout || "auto"}`, ""), [columns]);
41
51
  const headers = useMemo(() => withHeaders
42
52
  ? columns.reduce((acc, col, index) => [
@@ -46,6 +56,13 @@ function Table(_a) {
46
56
  : null, [withHeaders, columns]);
47
57
  return (React.createElement(Container, Object.assign({ gridTemplateColumns: gridTemplateColumns, gridAutoRows: "auto", columns: "none", alignItems: "center" }, containerProps),
48
58
  headers,
49
- React.createElement(Rows, { data: data, columns: columns, extraRender: extraRender })));
59
+ React.createElement(Rows, { data: data, columns: columns, extraRender: extraRender, renderRow: renderRow })));
50
60
  }
51
- export default memo(Table);
61
+ Table.Columns = Columns;
62
+ Table.ExtraRowContainer = ExtraRowContainer;
63
+ Table.RowContainer = RowContainer;
64
+ const memoTable = memo(Table);
65
+ memoTable.Columns = Columns;
66
+ memoTable.RowContainer = RowContainer;
67
+ memoTable.ExtraRowContainer = ExtraRowContainer;
68
+ export default memoTable;
@@ -1,10 +1,11 @@
1
1
  import React from "react";
2
2
  import { useTheme } from "styled-components";
3
3
  import Text from "../asorted/Text";
4
- import { IconColumn, TextColumn } from "./Columns";
4
+ import Table from "./index";
5
+ const { Columns } = Table;
5
6
  function Header({ children }) {
6
7
  const theme = useTheme();
7
- return (React.createElement(Text, { fontWeight: "semiBold", variant: "paragraph", style: { borderBottom: `1px solid ${theme.colors.palette.neutral.c40}` }, mx: -4, px: 4, pb: 8 }, children));
8
+ return (React.createElement(Text, { fontWeight: "semiBold", variant: "paragraph", style: { borderBottom: `1px solid ${theme.colors.neutral.c40}` }, mx: -4, px: 4, pb: 8 }, children));
8
9
  }
9
10
  export const balance = {
10
11
  data: [
@@ -42,31 +43,31 @@ export const balance = {
42
43
  },
43
44
  ],
44
45
  columns: [
45
- TextColumn({
46
+ Columns.text({
46
47
  header: () => React.createElement(Header, null, "Currency"),
47
48
  title: (elt) => elt.currency,
48
49
  }),
49
- TextColumn({
50
+ Columns.text({
50
51
  header: () => React.createElement(Header, null, "Amount"),
51
52
  title: (elt) => elt.amount,
52
53
  subtitle: (elt) => elt.counterValue,
53
54
  }),
54
- TextColumn({
55
+ Columns.text({
55
56
  header: () => React.createElement(Header, null, "Address"),
56
57
  subtitle: (elt) => elt.address,
57
58
  }),
58
- TextColumn({
59
+ Columns.text({
59
60
  header: () => React.createElement(Header, null, "Evolution"),
60
61
  subtitle: (elt) => (elt.evolution > 0 ? "+" : "") + elt.evolution,
61
62
  subtitleProps: (elt) => ({
62
- color: elt.evolution < 0 ? "palette.error.c100" : "palette.success.c100",
63
+ color: elt.evolution < 0 ? "error.c100" : "success.c100",
63
64
  }),
64
65
  }),
65
- IconColumn({
66
+ Columns.icon({
66
67
  header: () => React.createElement(Header, null, "\u00A0"),
67
68
  props: (elt) => ({
68
69
  name: "StarSolid",
69
- color: elt.starred ? "palette.neutral.c100" : "palette.neutral.c70",
70
+ color: elt.starred ? "neutral.c100" : "neutral.c70",
70
71
  }),
71
72
  }),
72
73
  ],
@@ -137,36 +138,36 @@ export const accounts = {
137
138
  layout: "64px",
138
139
  render: ({ elt }) => elt.currency.abbrev === "BTC" ? svgBtc : elt.currency.abbrev === "ETH" ? svgEth : svgUsdt,
139
140
  },
140
- TextColumn({
141
+ Columns.text({
141
142
  layout: "2fr",
142
143
  title: (elt) => elt.name,
143
144
  subtitle: (elt) => elt.currency.name,
144
145
  }),
145
- IconColumn({
146
+ Columns.icon({
146
147
  props: (elt) => ({
147
148
  name: elt.synchronized ? "CircledCheck" : "Clock",
148
- color: elt.synchronized ? "palette.success.c100" : "palette.neutral.c80",
149
+ color: elt.synchronized ? "success.c100" : "neutral.c80",
149
150
  }),
150
151
  }),
151
- TextColumn({
152
+ Columns.text({
152
153
  layout: "1fr",
153
154
  subtitle: (elt) => elt.currency.abbrev,
154
155
  }),
155
- TextColumn({
156
+ Columns.text({
156
157
  layout: "1fr",
157
158
  title: (elt) => elt.amount,
158
159
  }),
159
- TextColumn({
160
+ Columns.text({
160
161
  layout: "1fr",
161
162
  subtitle: (elt) => (elt.evolution > 0 ? "+" : "") + elt.evolution,
162
163
  subtitleProps: (elt) => ({
163
- color: elt.evolution < 0 ? "palette.error.c100" : "palette.success.c100",
164
+ color: elt.evolution < 0 ? "error.c100" : "success.c100",
164
165
  }),
165
166
  }),
166
- IconColumn({
167
+ Columns.icon({
167
168
  props: (elt) => ({
168
169
  name: "StarSolid",
169
- color: elt.starred ? "palette.neutral.c100" : "palette.neutral.c70",
170
+ color: elt.starred ? "neutral.c100" : "neutral.c70",
170
171
  }),
171
172
  }),
172
173
  ],
@@ -1,6 +1,10 @@
1
1
  import React from "react";
2
- import { BorderProps, ColorProps } from "styled-system";
3
- export declare type Props = React.PropsWithChildren<{
2
+ import { BorderProps } from "styled-system";
3
+ import { TextProps } from "../asorted/Text";
4
+ import { BaseStyledProps } from "../styled";
5
+ export declare type Size = "large" | "medium" | "small";
6
+ export declare type Type = "plain" | "opacity" | "outlined" | "outlinedOpacity";
7
+ export declare type TagProps = BaseStyledProps & BorderProps & React.PropsWithChildren<{
4
8
  /**
5
9
  * Changes the appearance based on the active state.
6
10
  */
@@ -8,6 +12,15 @@ export declare type Props = React.PropsWithChildren<{
8
12
  /**
9
13
  * Tag style.
10
14
  */
11
- type?: "plain" | "opacity" | "outlined";
12
- } & BorderProps & ColorProps>;
13
- export default function Tag({ children, ...props }: Props): JSX.Element;
15
+ type?: Type;
16
+ /**
17
+ * Size of the tag, affects the padding and the casing (uppercase for small and medium)
18
+ */
19
+ size?: Size;
20
+ /**
21
+ * Props passed to the text component, overriding props set internally by Tag component
22
+ */
23
+ textProps?: TextProps;
24
+ disabled?: boolean;
25
+ }>;
26
+ export default function Tag({ children, textProps, size, ...props }: TagProps): JSX.Element;