@usefui/components 1.5.3 → 1.7.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 (92) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/index.d.mts +615 -51
  3. package/dist/index.d.ts +615 -51
  4. package/dist/index.js +3154 -660
  5. package/dist/index.mjs +3131 -661
  6. package/package.json +12 -12
  7. package/src/__tests__/Avatar.test.tsx +55 -55
  8. package/src/__tests__/MessageBubble.test.tsx +179 -0
  9. package/src/__tests__/Shimmer.test.tsx +122 -0
  10. package/src/__tests__/Tree.test.tsx +275 -0
  11. package/src/accordion/Accordion.stories.tsx +6 -4
  12. package/src/accordion/hooks/index.tsx +3 -1
  13. package/src/accordion/index.tsx +1 -2
  14. package/src/avatar/Avatar.stories.tsx +37 -7
  15. package/src/avatar/index.tsx +90 -19
  16. package/src/avatar/styles/index.ts +58 -12
  17. package/src/badge/Badge.stories.tsx +27 -5
  18. package/src/badge/index.tsx +21 -14
  19. package/src/badge/styles/index.ts +69 -40
  20. package/src/button/Button.stories.tsx +40 -27
  21. package/src/button/index.tsx +13 -9
  22. package/src/button/styles/index.ts +308 -47
  23. package/src/card/index.tsx +2 -4
  24. package/src/checkbox/Checkbox.stories.tsx +72 -33
  25. package/src/checkbox/hooks/index.tsx +5 -1
  26. package/src/checkbox/index.tsx +8 -6
  27. package/src/checkbox/styles/index.ts +239 -19
  28. package/src/collapsible/Collapsible.stories.tsx +6 -4
  29. package/src/collapsible/hooks/index.tsx +3 -1
  30. package/src/dialog/Dialog.stories.tsx +173 -31
  31. package/src/dialog/hooks/index.tsx +5 -1
  32. package/src/dialog/styles/index.ts +15 -8
  33. package/src/dropdown/Dropdown.stories.tsx +61 -23
  34. package/src/dropdown/hooks/index.tsx +3 -1
  35. package/src/dropdown/index.tsx +51 -40
  36. package/src/dropdown/styles/index.ts +30 -19
  37. package/src/field/Field.stories.tsx +183 -24
  38. package/src/field/hooks/index.tsx +5 -1
  39. package/src/field/index.tsx +930 -13
  40. package/src/field/styles/index.ts +246 -14
  41. package/src/field/types/index.ts +31 -0
  42. package/src/field/utils/index.ts +201 -0
  43. package/src/index.ts +8 -1
  44. package/src/message-bubble/MessageBubble.stories.tsx +138 -0
  45. package/src/message-bubble/hooks/index.tsx +41 -0
  46. package/src/message-bubble/index.tsx +171 -0
  47. package/src/message-bubble/styles/index.ts +58 -0
  48. package/src/otp-field/OTPField.stories.tsx +22 -24
  49. package/src/otp-field/hooks/index.tsx +3 -1
  50. package/src/otp-field/index.tsx +14 -3
  51. package/src/otp-field/styles/index.ts +114 -16
  52. package/src/otp-field/types/index.ts +9 -1
  53. package/src/overlay/styles/index.ts +1 -0
  54. package/src/ruler/Ruler.stories.tsx +43 -0
  55. package/src/ruler/constants/index.ts +3 -0
  56. package/src/ruler/hooks/index.tsx +53 -0
  57. package/src/ruler/index.tsx +239 -0
  58. package/src/ruler/styles/index.tsx +154 -0
  59. package/src/ruler/types/index.ts +17 -0
  60. package/src/select/Select.stories.tsx +91 -0
  61. package/src/select/hooks/index.tsx +71 -0
  62. package/src/select/index.tsx +331 -0
  63. package/src/select/styles/index.tsx +156 -0
  64. package/src/sheet/hooks/index.tsx +5 -1
  65. package/src/shimmer/Shimmer.stories.tsx +97 -0
  66. package/src/shimmer/index.tsx +64 -0
  67. package/src/shimmer/styles/index.ts +33 -0
  68. package/src/skeleton/index.tsx +7 -6
  69. package/src/spinner/Spinner.stories.tsx +29 -4
  70. package/src/spinner/index.tsx +16 -6
  71. package/src/spinner/styles/index.ts +41 -22
  72. package/src/switch/Switch.stories.tsx +46 -17
  73. package/src/switch/hooks/index.tsx +5 -1
  74. package/src/switch/index.tsx +5 -8
  75. package/src/switch/styles/index.ts +45 -45
  76. package/src/tabs/Tabs.stories.tsx +43 -15
  77. package/src/tabs/hooks/index.tsx +5 -1
  78. package/src/text-area/Textarea.stories.tsx +45 -8
  79. package/src/text-area/index.tsx +9 -6
  80. package/src/text-area/styles/index.ts +1 -1
  81. package/src/toggle/Toggle.stories.tsx +6 -4
  82. package/src/toolbar/hooks/index.tsx +5 -1
  83. package/src/tree/Tree.stories.tsx +141 -0
  84. package/src/tree/hooks/tree-node-provider.tsx +50 -0
  85. package/src/tree/hooks/tree-provider.tsx +75 -0
  86. package/src/tree/index.tsx +231 -0
  87. package/src/tree/styles/index.ts +23 -0
  88. package/tsconfig.build.json +20 -0
  89. package/tsconfig.json +1 -3
  90. package/src/privacy-field/PrivacyField.stories.tsx +0 -29
  91. package/src/privacy-field/index.tsx +0 -56
  92. package/src/privacy-field/styles/index.ts +0 -17
@@ -1,6 +1,8 @@
1
1
  import React from "react";
2
2
  import type { Meta, StoryObj } from "@storybook/react";
3
3
  import { Badge } from "./";
4
+ import { Page } from "..";
5
+ import { ComponentSizeEnum } from "../../../../types";
4
6
 
5
7
  // Duplicated doc: The JSDoc content isn't rendering on Storybook.
6
8
 
@@ -20,9 +22,11 @@ const meta = {
20
22
  tags: ["autodocs"],
21
23
  decorators: [
22
24
  (Story) => (
23
- <div className="m-medium-30">
24
- <Story />
25
- </div>
25
+ <Page>
26
+ <Page.Content className="p-medium-30">
27
+ <Story />
28
+ </Page.Content>
29
+ </Page>
26
30
  ),
27
31
  ],
28
32
  } satisfies Meta<typeof Badge>;
@@ -35,7 +39,7 @@ export const Default: Story = {
35
39
  export const Shapes: Story = {
36
40
  render: ({ ...args }) => {
37
41
  return (
38
- <div className="flex g-medium-30">
42
+ <div className="flex flex column g-medium-30">
39
43
  <Badge shape="square">Square</Badge>
40
44
  <Badge shape="smooth">Smooth</Badge>
41
45
  <Badge shape="round">Round</Badge>
@@ -43,6 +47,23 @@ export const Shapes: Story = {
43
47
  );
44
48
  },
45
49
  };
50
+ export const Sizes: Story = {
51
+ render: ({ ...args }) => {
52
+ return (
53
+ <div className="flex align-start g-medium-30">
54
+ <Badge variant="border" sizing="small">
55
+ Label
56
+ </Badge>
57
+ <Badge variant="border" sizing="medium">
58
+ Label
59
+ </Badge>
60
+ <Badge variant="border" sizing="large">
61
+ Label
62
+ </Badge>
63
+ </div>
64
+ );
65
+ },
66
+ };
46
67
  export const Variants: Story = {
47
68
  render: ({ ...args }) => {
48
69
  return (
@@ -51,9 +72,10 @@ export const Variants: Story = {
51
72
  <Badge variant="secondary">Secondary</Badge>
52
73
  <Badge variant="border">Border</Badge>
53
74
  <Badge variant="meta">Meta</Badge>
75
+ <Badge variant="hint">Hint</Badge>
54
76
  <Badge variant="success">Success</Badge>
55
77
  <Badge variant="warning">Warning</Badge>
56
- <Badge variant="error">Error</Badge>
78
+ <Badge variant="danger">Error</Badge>
57
79
  </div>
58
80
  );
59
81
  },
@@ -3,20 +3,24 @@
3
3
  import React from "react";
4
4
  import { BadgeWrapper } from "./styles";
5
5
 
6
- import type { IComponentStyling, TComponentShape } from "../../../../types";
6
+ import {
7
+ ComponentShapeEnum,
8
+ ComponentSizeEnum,
9
+ ComponentVariantEnum,
10
+ IComponentSize,
11
+ TComponentVariant,
12
+ TComponentVariantExtended,
13
+ type IComponentShape,
14
+ type IComponentStyling,
15
+ } from "../../../../types";
7
16
 
8
- interface IBadgeProperties
9
- extends IComponentStyling,
17
+ export interface IBadgeProperties
18
+ extends
19
+ IComponentStyling,
20
+ IComponentShape,
21
+ IComponentSize,
10
22
  React.ComponentProps<"div"> {
11
- variant?:
12
- | "primary"
13
- | "secondary"
14
- | "border"
15
- | "error"
16
- | "warning"
17
- | "success"
18
- | "meta";
19
- shape?: TComponentShape;
23
+ variant?: TComponentVariant | TComponentVariantExtended;
20
24
  }
21
25
 
22
26
  /**
@@ -30,6 +34,7 @@ interface IBadgeProperties
30
34
  * @param {IBadgeProperties} props - The props for the Badge component.
31
35
  * @param {boolean} props.raw - Define whether the component is styled or not.
32
36
  * @param {TComponentShape} props.shape - The shape of the component. Defaults to `smooth`.
37
+ * @param {ComponentSizeEnum} props.sizing - The size of the component. Defaults to "small".
33
38
  * @param {string} props.variant - The style definition used by the component.
34
39
  * @param {ReactNode} props.children - The content to be rendered inside the Badge.
35
40
  * @returns {ReactElement} The Badge component.
@@ -37,8 +42,9 @@ interface IBadgeProperties
37
42
  export const Badge = (props: IBadgeProperties) => {
38
43
  const {
39
44
  raw = false,
40
- variant = "primary",
41
- shape = "smooth",
45
+ sizing = ComponentSizeEnum.Small,
46
+ variant = ComponentVariantEnum.Primary,
47
+ shape = ComponentShapeEnum.Smooth,
42
48
  children,
43
49
  ...restProps
44
50
  } = props;
@@ -48,6 +54,7 @@ export const Badge = (props: IBadgeProperties) => {
48
54
  data-raw={raw}
49
55
  data-variant={variant}
50
56
  data-shape={shape}
57
+ data-size={sizing}
51
58
  {...restProps}
52
59
  >
53
60
  {children}
@@ -1,91 +1,98 @@
1
1
  import styled, { css } from "styled-components";
2
2
 
3
3
  const BadgeBaseStyles = css`
4
- display: inline-flex;
4
+ display: flex;
5
5
  align-items: center;
6
6
  justify-content: center;
7
7
  gap: var(--measurement-medium-10);
8
+
8
9
  min-width: var(--measurement-medium-60);
9
10
  min-height: var(--measurement-medium-60);
10
11
  width: fit-content;
11
12
 
12
13
  border: var(--measurement-small-10) solid transparent;
14
+ padding: 0 var(--measurement-medium-30);
13
15
 
14
16
  font-size: var(--fontsize-small-60);
15
- padding: var(--measurement-medium-10) var(--measurement-medium-30);
16
17
  font-weight: 500;
18
+ letter-spacing: calc(
19
+ var(--fontsize-small-10) - ((var(--fontsize-small-10) * 1.066))
20
+ );
21
+ line-height: 0;
22
+
17
23
  transition: all ease-in-out 0.2s;
18
24
  `;
19
-
20
25
  const BadgeVariantStyles = css`
21
26
  border: var(--measurement-small-10) solid transparent;
22
27
 
23
28
  &[data-variant="primary"] {
24
- background-color: var(--font-color);
25
- color: var(--body-color);
29
+ background-color: var(--font-color-alpha-10);
30
+ color: var(--font-color-alpha-80);
26
31
 
27
- &:hover,
28
- &:focus {
29
- border-color: var(--font-color-alpha-10);
32
+ * {
33
+ color: currentColor !important;
30
34
  }
31
35
  }
32
36
  &[data-variant="secondary"] {
33
- background-color: var(--font-color-alpha-10);
34
- color: var(--font-color-alpha-60);
37
+ background-color: var(--contrast-color);
38
+ color: var(--font-color-alpha-80);
35
39
 
36
- &:hover,
37
- &:focus {
38
- color: var(--font-color);
40
+ * {
41
+ color: currentColor !important;
39
42
  }
40
43
  }
41
44
  &[data-variant="border"] {
42
45
  background-color: transparent;
43
46
  border-color: var(--font-color-alpha-10);
44
- color: var(--font-color-alpha-60);
47
+ color: var(--font-color-alpha-80);
45
48
 
46
- &:hover,
47
- &:focus {
48
- color: var(--font-color);
49
+ * {
50
+ color: currentColor !important;
49
51
  }
50
52
  }
51
- &[data-variant="error"] {
53
+ &[data-variant="danger"] {
52
54
  background-color: var(--alpha-red-10);
53
- color: var(--alpha-red-80);
55
+ border-color: var(--alpha-red-10);
56
+ color: var(--shade-red-20);
54
57
 
55
- &:hover,
56
- &:focus {
57
- background-color: var(--alpha-red-10);
58
- color: var(--color-red);
58
+ * {
59
+ color: currentColor !important;
59
60
  }
60
61
  }
61
62
  &[data-variant="warning"] {
62
63
  background-color: var(--alpha-orange-10);
63
- color: var(--alpha-orange-80);
64
+ border-color: var(--alpha-orange-10);
65
+ color: var(--shade-orange-20);
64
66
 
65
- &:hover,
66
- &:focus {
67
- background-color: var(--alpha-orange-10);
68
- color: var(--color-orange);
67
+ * {
68
+ color: currentColor !important;
69
69
  }
70
70
  }
71
71
  &[data-variant="success"] {
72
72
  background-color: var(--alpha-green-10);
73
- color: var(--alpha-green-80);
73
+ border-color: var(--alpha-green-10);
74
+ color: var(--shade-lime-20);
74
75
 
75
- &:hover,
76
- &:focus {
77
- background-color: var(--alpha-green-10);
78
- color: var(--color-green);
76
+ * {
77
+ color: currentColor !important;
79
78
  }
80
79
  }
81
80
  &[data-variant="meta"] {
82
- background-color: var(--alpha-blue-10);
83
- color: var(--alpha-blue-80);
81
+ background-color: var(--alpha-indigo-10);
82
+ border-color: var(--alpha-indigo-10);
83
+ color: var(--shade-indigo-20);
84
+
85
+ * {
86
+ color: currentColor !important;
87
+ }
88
+ }
89
+ &[data-variant="hint"] {
90
+ background-color: var(--alpha-purple-10);
91
+ border-color: var(--alpha-purple-10);
92
+ color: var(--shade-purple-20);
84
93
 
85
- &:hover,
86
- &:focus {
87
- background-color: var(--alpha-blue-10);
88
- color: var(--color-blue);
94
+ * {
95
+ color: currentColor !important;
89
96
  }
90
97
  }
91
98
  `;
@@ -97,13 +104,35 @@ const BadgeShapeStyles = css`
97
104
  border-radius: var(--measurement-medium-20);
98
105
  }
99
106
  &[data-shape="round"] {
100
- border-radius: var(--measurement-large-90);
107
+ border-radius: var(--measurement-medium-60);
101
108
  }
102
109
  `;
110
+ const BadgeSizeStyles = css`
111
+ &[data-size="small"] {
112
+ padding: 0 var(--measurement-medium-30);
113
+
114
+ min-width: var(--measurement-medium-70);
115
+ min-height: var(--measurement-medium-70);
116
+ }
117
+ &[data-size="medium"] {
118
+ padding: 0 var(--measurement-medium-40);
119
+
120
+ min-width: var(--fontsize-medium-60);
121
+ min-height: var(--fontsize-medium-60);
122
+ }
123
+ &[data-size="large"] {
124
+ padding: 0 var(--measurement-medium-40);
125
+
126
+ min-width: var(--fontsize-medium-70);
127
+ min-height: var(--fontsize-medium-70);
128
+ }
129
+ `;
130
+
103
131
  export const BadgeWrapper = styled.div<any>`
104
132
  &[data-raw="false"] {
105
133
  ${BadgeBaseStyles}
106
134
  ${BadgeVariantStyles}
107
135
  ${BadgeShapeStyles}
136
+ ${BadgeSizeStyles}
108
137
  }
109
138
  `;
@@ -8,9 +8,11 @@ const meta = {
8
8
  tags: ["autodocs"],
9
9
  decorators: [
10
10
  (Story) => (
11
- <div className="m-medium-30">
12
- <Story />
13
- </div>
11
+ <Page>
12
+ <Page.Content className="p-medium-30">
13
+ <Story />
14
+ </Page.Content>
15
+ </Page>
14
16
  ),
15
17
  ],
16
18
  } satisfies Meta<typeof Button>;
@@ -46,15 +48,28 @@ export const Variants: Story = {
46
48
  render: ({ ...args }) => {
47
49
  return (
48
50
  <Page>
49
- <Page.Content className="flex align-center justify-center">
51
+ <Page.Content className="flex flex-column g-medium-30 align-center justify-center">
52
+ <div className="flex align-center justify-center g-medium-30 flex-wrap">
53
+ <Button variant="accent">
54
+ <span className="color-mono-white">Accent</span>
55
+ </Button>
56
+ </div>
50
57
  <div className="flex align-center justify-center g-medium-30 flex-wrap">
51
58
  <Button variant="primary">Primary</Button>
52
59
  <Button variant="secondary">Secondary</Button>
53
60
  <Button variant="tertiary">Tertiary</Button>
54
- <Button variant="danger">Danger</Button>
55
- <Button variant="warning">Warning</Button>
56
61
  <Button variant="mono">Mono</Button>
57
62
  <Button variant="border">Border</Button>
63
+ </div>
64
+ <div className="flex align-center justify-center g-medium-30 flex-wrap">
65
+ <Button variant="hint">Hint</Button>
66
+ <Button variant="meta">Meta</Button>
67
+ <Button variant="success">Success</Button>
68
+ <Button variant="danger">Danger</Button>
69
+ <Button variant="warning">Warning</Button>
70
+ </div>
71
+ <div className="flex align-center justify-center g-medium-30 flex-wrap">
72
+ <Button variant="link">Link</Button>
58
73
  <Button variant="ghost">Ghost</Button>
59
74
  </div>
60
75
  </Page.Content>
@@ -67,6 +82,11 @@ export const Animations: Story = {
67
82
  return (
68
83
  <Page>
69
84
  <Page.Content className="flex flex-column g-medium-30 align-center justify-center">
85
+ <div className="flex align-center justify-center g-medium-30 flex-wrap">
86
+ <Button animation="reflective" variant="accent">
87
+ <span className="color-mono-white">Accent</span>
88
+ </Button>
89
+ </div>
70
90
  <div className="flex align-center justify-center g-medium-30 flex-wrap">
71
91
  <Button animation="reflective" variant="primary">
72
92
  Primary
@@ -77,12 +97,6 @@ export const Animations: Story = {
77
97
  <Button animation="reflective" variant="tertiary">
78
98
  Tertiary
79
99
  </Button>
80
- <Button animation="reflective" variant="danger">
81
- Danger
82
- </Button>
83
- <Button animation="reflective" variant="warning">
84
- Warning
85
- </Button>
86
100
  <Button animation="reflective" variant="mono">
87
101
  Mono
88
102
  </Button>
@@ -91,27 +105,26 @@ export const Animations: Story = {
91
105
  </Button>
92
106
  </div>
93
107
  <div className="flex align-center justify-center g-medium-30 flex-wrap">
94
- <Button animation="reflective" variant="border" sizing="small">
95
- Small
108
+ <Button animation="reflective" variant="hint">
109
+ Hint
96
110
  </Button>
97
- <Button animation="reflective" variant="border" sizing="medium">
98
- Medium
111
+ <Button animation="reflective" variant="meta">
112
+ Meta
99
113
  </Button>
100
- <Button animation="reflective" variant="border" sizing="large">
101
- Large
114
+ <Button animation="reflective" variant="success">
115
+ Success
102
116
  </Button>
103
- </div>
104
- <div className="flex align-center justify-center g-medium-30 flex-wrap">
105
- <Button animation="reflective" variant="border" shape="square">
106
- Square
107
- </Button>
108
- <Button animation="reflective" variant="border" shape="smooth">
109
- Smooth
117
+ <Button animation="reflective" variant="danger">
118
+ Danger
110
119
  </Button>
111
- <Button animation="reflective" variant="border" shape="round">
112
- Round
120
+ <Button animation="reflective" variant="warning">
121
+ Warning
113
122
  </Button>
114
123
  </div>
124
+ <div className="flex align-center justify-center g-medium-30 flex-wrap">
125
+ <Button variant="link">Link</Button>
126
+ <Button variant="ghost">Ghost</Button>
127
+ </div>
115
128
  </Page.Content>
116
129
  </Page>
117
130
  );
@@ -9,16 +9,20 @@ import {
9
9
  IComponentSize,
10
10
  ComponentVariantEnum,
11
11
  TComponentVariant,
12
- TComponentShape,
12
+ ComponentShapeEnum,
13
+ IComponentShape,
14
+ TComponentVariantExtended,
13
15
  } from "../../../../types";
14
16
 
15
17
  export interface IButtonProperties
16
- extends IComponentStyling,
18
+ extends
19
+ IComponentStyling,
20
+ IComponentShape,
17
21
  IComponentSize,
18
22
  React.ComponentPropsWithRef<"button"> {
19
23
  rawicon?: boolean;
20
- variant?: TComponentVariant | "danger" | "warning";
21
- shape?: TComponentShape;
24
+ variant?: TComponentVariant | TComponentVariantExtended | "link" | "accent";
25
+
22
26
  animation?: "reflective";
23
27
  }
24
28
 
@@ -46,7 +50,7 @@ export const Button = React.forwardRef<HTMLButtonElement, IButtonProperties>(
46
50
  name,
47
51
  variant = ComponentVariantEnum.Primary,
48
52
  sizing = ComponentSizeEnum.Medium,
49
- shape = "smooth",
53
+ shape = ComponentShapeEnum.Smooth,
50
54
  animation,
51
55
  raw,
52
56
  rawicon,
@@ -82,7 +86,7 @@ export const Button = React.forwardRef<HTMLButtonElement, IButtonProperties>(
82
86
  y: ((e.clientY - rect.top) / rect.height) * 100,
83
87
  });
84
88
  },
85
- []
89
+ [],
86
90
  );
87
91
  const handleMouseEnter = React.useCallback(
88
92
  (e: React.MouseEvent<HTMLButtonElement>) => {
@@ -91,7 +95,7 @@ export const Button = React.forwardRef<HTMLButtonElement, IButtonProperties>(
91
95
 
92
96
  setIsHovering(true);
93
97
  },
94
- []
98
+ [],
95
99
  );
96
100
  const handleMouseLeave = React.useCallback(
97
101
  (e: React.MouseEvent<HTMLButtonElement>) => {
@@ -100,7 +104,7 @@ export const Button = React.forwardRef<HTMLButtonElement, IButtonProperties>(
100
104
 
101
105
  setIsHovering(false);
102
106
  },
103
- []
107
+ [],
104
108
  );
105
109
 
106
110
  return (
@@ -136,6 +140,6 @@ export const Button = React.forwardRef<HTMLButtonElement, IButtonProperties>(
136
140
  {children}
137
141
  </ButtonWrapper>
138
142
  );
139
- }
143
+ },
140
144
  );
141
145
  Button.displayName = "Button";