@altinn/altinn-components 0.4.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 (194) hide show
  1. package/.storybook/main.ts +1 -1
  2. package/CHANGELOG.md +14 -0
  3. package/biome.jsonc +1 -1
  4. package/lib/components/Attachment/AttachmentLink.stories.ts +1 -1
  5. package/lib/components/Attachment/AttachmentList.stories.ts +1 -1
  6. package/lib/components/Button/Button.tsx +13 -10
  7. package/lib/components/Button/ButtonBase.tsx +1 -1
  8. package/lib/components/Button/ButtonIcon.tsx +16 -0
  9. package/lib/components/Button/ButtonLabel.tsx +16 -0
  10. package/lib/components/Button/Buttons.stories.tsx +64 -0
  11. package/lib/components/Button/ComboButton.tsx +9 -7
  12. package/lib/components/Button/IconButton.stories.tsx +47 -0
  13. package/lib/components/Button/IconButton.tsx +15 -5
  14. package/lib/components/Button/button.module.css +5 -46
  15. package/lib/components/Button/buttonBase.module.css +55 -23
  16. package/lib/components/Button/buttonIcon.module.css +17 -0
  17. package/lib/components/Button/buttonLabel.module.css +17 -0
  18. package/lib/components/Button/comboButton.module.css +15 -65
  19. package/lib/components/Button/iconButton.module.css +21 -4
  20. package/lib/components/Button/index.ts +2 -0
  21. package/lib/components/ContextMenu/ContextMenu.stories.ts +49 -0
  22. package/lib/components/ContextMenu/ContextMenu.tsx +12 -20
  23. package/lib/components/ContextMenu/ContextMenuBase.tsx +33 -0
  24. package/lib/components/Dialog/Dialog.tsx +2 -0
  25. package/lib/components/Dialog/DialogGroup.tsx +24 -0
  26. package/lib/components/Dialog/DialogList.stories.ts +14 -10
  27. package/lib/components/Dialog/DialogList.tsx +26 -11
  28. package/lib/components/Dialog/DialogListItem.tsx +12 -3
  29. package/lib/components/Dialog/DialogListItemBase.tsx +4 -2
  30. package/lib/components/Dialog/DialogNav.stories.ts +5 -5
  31. package/lib/components/Dialog/DialogNav.tsx +3 -7
  32. package/lib/components/Dialog/DialogSelect.tsx +1 -1
  33. package/lib/components/Dialog/dialogGroup.module.css +35 -0
  34. package/lib/components/Dialog/dialogNav.module.css +12 -0
  35. package/lib/components/Dropdown/Backdrop.tsx +4 -3
  36. package/lib/components/Dropdown/DrawerBase.tsx +5 -2
  37. package/lib/components/Dropdown/DrawerBody.tsx +12 -0
  38. package/lib/components/Dropdown/DrawerButton.tsx +17 -0
  39. package/lib/components/Dropdown/DrawerFooter.tsx +12 -0
  40. package/lib/components/Dropdown/DrawerHeader.tsx +19 -0
  41. package/lib/components/Dropdown/DrawerOrDropdown.tsx +29 -0
  42. package/lib/components/Dropdown/DropdownBase.tsx +5 -2
  43. package/lib/components/Dropdown/backdrop.module.css +3 -0
  44. package/lib/components/Dropdown/drawerBase.module.css +9 -0
  45. package/lib/components/Dropdown/drawerBody.module.css +5 -0
  46. package/lib/components/Dropdown/drawerButton.module.css +6 -0
  47. package/lib/components/Dropdown/drawerFooter.module.css +13 -0
  48. package/lib/components/Dropdown/drawerHeader.module.css +17 -0
  49. package/lib/components/Dropdown/drawerOrDropdown.module.css +19 -0
  50. package/lib/components/Dropdown/dropdownBase.module.css +15 -3
  51. package/lib/components/Dropdown/index.ts +7 -1
  52. package/lib/components/Footer/footerMenu.module.css +5 -0
  53. package/lib/components/GlobalMenu/GlobalMenu.stories.tsx +9 -9
  54. package/lib/components/GlobalMenu/GlobalMenu.tsx +5 -5
  55. package/lib/components/Header/{Header.stories.ts → Header.stories.tsx} +79 -20
  56. package/lib/components/Header/Header.tsx +24 -42
  57. package/lib/components/Header/HeaderBase.tsx +7 -3
  58. package/lib/components/Header/header.module.css +10 -42
  59. package/lib/components/Header/headerBase.module.css +43 -0
  60. package/lib/components/Header/headerButton.module.css +1 -0
  61. package/lib/components/History/HistoryAttachments.tsx +22 -0
  62. package/lib/components/History/HistoryItem.stories.ts +27 -18
  63. package/lib/components/History/HistoryItem.tsx +7 -15
  64. package/lib/components/History/HistoryList.stories.ts +34 -22
  65. package/lib/components/Layout/Layout.stories.tsx +77 -38
  66. package/lib/components/Layout/Layout.tsx +5 -3
  67. package/lib/components/Layout/LayoutBase.tsx +4 -3
  68. package/lib/components/Layout/index.tsx +1 -0
  69. package/lib/components/Layout/layoutBase.module.css +9 -10
  70. package/lib/components/Layout/layoutBody.module.css +1 -0
  71. package/lib/components/Layout/layoutContent.module.css +6 -1
  72. package/lib/components/Layout/layoutSidebar.module.css +1 -0
  73. package/lib/components/LayoutAction/ActionFooter.stories.tsx +1 -1
  74. package/lib/components/LayoutAction/ActionHeader.tsx +2 -2
  75. package/lib/components/LayoutAction/ActionMenu.stories.tsx +1 -0
  76. package/lib/components/LayoutAction/ActionMenu.tsx +4 -3
  77. package/lib/components/LayoutAction/actionMenu.module.css +11 -6
  78. package/lib/components/List/List.stories.tsx +43 -0
  79. package/lib/components/List/List.tsx +6 -6
  80. package/lib/components/List/ListBase.tsx +6 -6
  81. package/lib/components/List/ListItem.tsx +4 -1
  82. package/lib/components/List/ListItemBase.tsx +20 -4
  83. package/lib/components/List/listBase.module.css +3 -3
  84. package/lib/components/List/listItemBase.module.css +4 -0
  85. package/lib/components/Menu/Menu.stories.ts +46 -46
  86. package/lib/components/Menu/Menu.tsx +3 -102
  87. package/lib/components/Menu/MenuBase.tsx +47 -3
  88. package/lib/components/Menu/{MenuItem.stories.ts → MenuItem.stories.tsx} +32 -0
  89. package/lib/components/Menu/MenuItem.tsx +6 -4
  90. package/lib/components/Menu/MenuItemBase.tsx +8 -1
  91. package/lib/components/Menu/MenuItems.stories.ts +438 -0
  92. package/lib/components/Menu/MenuItems.tsx +96 -0
  93. package/lib/components/Menu/MenuOption.tsx +4 -1
  94. package/lib/components/Menu/{MenuGroup.tsx → __MenuGroup.tsx} +1 -1
  95. package/lib/components/Menu/{menuItem.module.css → __menuItem.module.css} +0 -6
  96. package/lib/components/Menu/index.ts +1 -1
  97. package/lib/components/Menu/menu.module.css +2 -3
  98. package/lib/components/Menu/menuBase.module.css +25 -0
  99. package/lib/components/Menu/menuItemBase.module.css +12 -17
  100. package/lib/components/Menu/menuItemMedia.module.css +2 -0
  101. package/lib/components/Meta/MetaItemBase.tsx +1 -1
  102. package/lib/components/Meta/MetaItemLabel.tsx +1 -1
  103. package/lib/components/Meta/MetaItemMedia.tsx +1 -1
  104. package/lib/components/Page/PageBase.tsx +14 -0
  105. package/lib/components/Page/PageHeader.tsx +21 -0
  106. package/lib/components/Page/PageHeaderMedia.tsx +25 -0
  107. package/lib/components/Page/SectionBase.tsx +52 -0
  108. package/lib/components/Page/SectionFooter.tsx +15 -0
  109. package/lib/components/Page/SectionHeader.tsx +16 -0
  110. package/lib/components/Page/index.ts +5 -0
  111. package/lib/components/Page/pageHeader.module.css +5 -0
  112. package/lib/components/Page/sectionBase.module.css +82 -0
  113. package/lib/components/Page/sectionFooter.module.css +8 -0
  114. package/lib/components/Page/sectionHeader.module.css +9 -0
  115. package/lib/components/RootProvider/RootProvider.tsx +43 -7
  116. package/lib/components/Searchbar/Autocomplete.stories.tsx +77 -0
  117. package/lib/components/Searchbar/Autocomplete.tsx +44 -0
  118. package/lib/components/Searchbar/AutocompleteBase.tsx +16 -0
  119. package/lib/components/Searchbar/AutocompleteGroup.tsx +17 -0
  120. package/lib/components/Searchbar/AutocompleteItem.tsx +23 -0
  121. package/lib/components/Searchbar/SearchField.tsx +78 -0
  122. package/lib/components/Searchbar/Searchbar.stories.tsx +151 -0
  123. package/lib/components/Searchbar/Searchbar.tsx +18 -0
  124. package/lib/components/Searchbar/SearchbarBase.tsx +23 -0
  125. package/lib/components/Searchbar/autocompleteBase.module.css +17 -0
  126. package/lib/components/Searchbar/autocompleteGroup.module.css +3 -0
  127. package/lib/components/Searchbar/autocompleteItem.module.css +19 -0
  128. package/lib/components/Searchbar/index.ts +1 -0
  129. package/lib/components/Searchbar/searchField.module.css +54 -0
  130. package/lib/components/Searchbar/searchbarBase.module.css +20 -0
  131. package/lib/components/Toolbar/Toolbar.stories.tsx +10 -10
  132. package/lib/components/Toolbar/Toolbar.tsx +28 -10
  133. package/lib/components/Toolbar/ToolbarAdd.tsx +6 -5
  134. package/lib/components/Toolbar/ToolbarBase.tsx +5 -20
  135. package/lib/components/Toolbar/ToolbarButton.tsx +1 -1
  136. package/lib/components/Toolbar/ToolbarFilter.tsx +11 -6
  137. package/lib/components/Toolbar/ToolbarMenu.tsx +8 -7
  138. package/lib/components/Toolbar/ToolbarOptions.stories.ts +5 -5
  139. package/lib/components/Toolbar/ToolbarOptions.tsx +34 -21
  140. package/lib/components/Toolbar/toolbarAdd.module.css +7 -0
  141. package/lib/components/Toolbar/toolbarBase.module.css +19 -0
  142. package/lib/components/Toolbar/toolbarButton.module.css +1 -1
  143. package/lib/components/Toolbar/toolbarFilter.module.css +25 -0
  144. package/lib/components/Toolbar/toolbarMenu.module.css +7 -0
  145. package/lib/components/Typography/Heading.tsx +23 -0
  146. package/lib/components/Typography/Typography.tsx +8 -5
  147. package/lib/components/Typography/heading.module.css +21 -0
  148. package/lib/components/Typography/index.ts +1 -0
  149. package/lib/components/Typography/typography.module.css +8 -0
  150. package/lib/components/index.ts +2 -0
  151. package/lib/css/global.css +1 -0
  152. package/lib/css/theme-global-dark.css +19 -0
  153. package/lib/hooks/index.ts +3 -0
  154. package/lib/{components/Menu → hooks}/useEscapeKey.ts +2 -2
  155. package/lib/hooks/useMenu.tsx +80 -0
  156. package/lib/index.ts +1 -0
  157. package/lib/stories/Color/MenuItem.stories.tsx +43 -0
  158. package/lib/stories/Color/Swatches.stories.tsx +19 -0
  159. package/lib/stories/Color/Swatches.tsx +42 -0
  160. package/lib/stories/Color/colors.json +62 -0
  161. package/lib/stories/Color/swatches.module.css +14 -0
  162. package/lib/stories/Inbox/BookmarksPage.tsx +52 -0
  163. package/lib/stories/Inbox/DialogPage.tsx +15 -0
  164. package/lib/stories/Inbox/Inbox.stories.tsx +55 -0
  165. package/lib/stories/Inbox/Inbox.tsx +12 -0
  166. package/lib/stories/Inbox/InboxLayout.tsx +50 -0
  167. package/lib/stories/Inbox/InboxPage.tsx +50 -0
  168. package/lib/stories/Inbox/InboxProvider.tsx +136 -0
  169. package/lib/stories/Inbox/InboxSection.tsx +39 -0
  170. package/lib/stories/Inbox/InboxToolbar.tsx +94 -0
  171. package/lib/stories/Inbox/ProfilePage.tsx +35 -0
  172. package/lib/stories/Inbox/SettingsPage.tsx +19 -0
  173. package/lib/stories/Inbox/accounts/accounts.ts +24 -0
  174. package/lib/stories/Inbox/accounts/index.ts +1 -0
  175. package/lib/stories/Inbox/actionMenu.ts +24 -0
  176. package/lib/stories/Inbox/dialogs/brreg-completed.json +35 -0
  177. package/lib/stories/Inbox/dialogs/brreg-draft.json +45 -0
  178. package/lib/stories/Inbox/dialogs/index.ts +10 -0
  179. package/lib/stories/Inbox/dialogs/skatt-2023.json +33 -0
  180. package/lib/stories/Inbox/groupBy.ts +19 -0
  181. package/lib/stories/Inbox/inboxSection.module.css +19 -0
  182. package/lib/stories/Inbox/index.ts +15 -0
  183. package/lib/stories/Inbox/layout/footer.ts +27 -0
  184. package/lib/stories/Inbox/layout/header.ts +11 -0
  185. package/lib/stories/Inbox/layout/index.ts +3 -0
  186. package/lib/stories/Inbox/layout/menu.ts +64 -0
  187. package/package.json +1 -1
  188. package/tsconfig.json +7 -2
  189. package/lib/components/Header/HeaderSearch.stories.ts +0 -20
  190. package/lib/components/Header/HeaderSearch.tsx +0 -44
  191. package/lib/components/Header/headerSearch.module.css +0 -30
  192. package/lib/components/Toolbar/toolbar.module.css +0 -43
  193. /package/lib/components/ContextMenu/{contextMenu.module.css → contextMenuBase.module.css} +0 -0
  194. /package/lib/{components/Menu → hooks}/useClickOutside.ts +0 -0
@@ -1,7 +1,7 @@
1
1
  import { StorybookConfig } from "@storybook/react-vite";
2
2
 
3
3
  const config: StorybookConfig = {
4
- stories: ["../lib/components/**/*.stories.@(ts|tsx)"],
4
+ stories: ["../lib/components/**/*.stories.@(ts|tsx)", "../lib/stories/**/*.stories.@(ts|tsx)"],
5
5
  addons: [
6
6
  "@storybook/addon-onboarding",
7
7
  "@storybook/addon-links",
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0](https://github.com/Altinn/altinn-components/compare/v0.4.1...v0.5.0) (2024-11-15)
4
+
5
+
6
+ ### Features
7
+
8
+ * search bar ([#45](https://github.com/Altinn/altinn-components/issues/45)) ([cc908e0](https://github.com/Altinn/altinn-components/commit/cc908e05957783adf97b94d5e196bf9722523471))
9
+
10
+ ## [0.4.1](https://github.com/Altinn/altinn-components/compare/v0.4.0...v0.4.1) (2024-11-11)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * css changes to dialog ([#43](https://github.com/Altinn/altinn-components/issues/43)) ([79e3287](https://github.com/Altinn/altinn-components/commit/79e3287dc2efbce8ba7a9c0b94f955514289c0d3))
16
+
3
17
  ## [0.4.0](https://github.com/Altinn/altinn-components/compare/v0.3.0...v0.4.0) (2024-11-08)
4
18
 
5
19
 
package/biome.jsonc CHANGED
@@ -60,6 +60,6 @@
60
60
  }
61
61
  },
62
62
  "files": {
63
- "ignore": [".github", "node_modules", "dist", "build", ".storybook"]
63
+ "ignore": [".github", "node_modules", "dist", "build", ".storybook", "lib/stories"]
64
64
  }
65
65
  }
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react';
2
2
  import { AttachmentLink } from './AttachmentLink';
3
3
 
4
4
  const meta = {
5
- title: 'Attachment/AttachmentLink',
5
+ title: 'Atoms/Attachment/AttachmentLink',
6
6
  component: AttachmentLink,
7
7
  tags: ['autodocs'],
8
8
  parameters: {},
@@ -4,7 +4,7 @@ import { fn } from '@storybook/test';
4
4
  import { AttachmentList } from './AttachmentList';
5
5
 
6
6
  const meta = {
7
- title: 'Attachment/AttachmentList',
7
+ title: 'Atoms/Attachment/AttachmentList',
8
8
  component: AttachmentList,
9
9
  tags: ['autodocs'],
10
10
  parameters: {
@@ -1,6 +1,8 @@
1
1
  import cx from 'classnames';
2
- import { Icon, type IconName } from '../Icon';
2
+ import type { IconName } from '../Icon';
3
3
  import { ButtonBase, type ButtonBaseProps } from './ButtonBase';
4
+ import { ButtonIcon } from './ButtonIcon';
5
+ import { ButtonLabel } from './ButtonLabel';
4
6
  import styles from './button.module.css';
5
7
 
6
8
  export interface ButtonProps extends Partial<ButtonBaseProps> {
@@ -10,22 +12,27 @@ export interface ButtonProps extends Partial<ButtonBaseProps> {
10
12
  }
11
13
 
12
14
  export const Button = ({
15
+ variant = 'solid',
16
+ color = 'primary',
13
17
  size = 'md',
14
18
  reverse = false,
15
19
  selected = false,
16
20
  icon,
17
21
  href,
18
22
  children,
23
+ className,
19
24
  loading,
20
25
  ...rest
21
26
  }: ButtonProps) => {
22
27
  if (loading) {
23
28
  return (
24
29
  <ButtonBase
30
+ variant={variant}
31
+ color={color}
25
32
  size={size}
26
33
  selected={selected}
27
34
  href={href}
28
- className={cx(styles.button, { [styles.reverse]: reverse })}
35
+ className={cx(styles.button, { [styles.reverse]: reverse }, className)}
29
36
  {...rest}
30
37
  disabled
31
38
  >
@@ -38,20 +45,16 @@ export const Button = ({
38
45
 
39
46
  return (
40
47
  <ButtonBase
48
+ variant={variant}
49
+ color={color}
41
50
  size={size}
42
51
  selected={selected}
43
52
  href={href}
44
53
  className={cx(styles.button, { [styles.reverse]: reverse })}
45
54
  {...rest}
46
55
  >
47
- <span className={styles.label} data-size={size}>
48
- {children}
49
- </span>
50
- {icon && (
51
- <span className={styles.icon} data-size={size}>
52
- <Icon name={icon} />
53
- </span>
54
- )}
56
+ <ButtonLabel size={size}>{children}</ButtonLabel>
57
+ {icon && <ButtonIcon size={size} icon={icon} />}
55
58
  </ButtonBase>
56
59
  );
57
60
  };
@@ -4,7 +4,7 @@ import type { ElementType, ReactNode } from 'react';
4
4
  import styles from './buttonBase.module.css';
5
5
 
6
6
  export type ButtonVariant = 'solid' | 'outline' | 'dotted' | 'text';
7
- export type ButtonSize = 'sm' | 'md' | 'lg';
7
+ export type ButtonSize = 'sm' | 'md' | 'lg' | 'custom';
8
8
  export type ButtonColor = 'primary' | 'secondary';
9
9
 
10
10
  export interface ButtonBaseProps extends React.HTMLAttributes<HTMLButtonElement> {
@@ -0,0 +1,16 @@
1
+ import { Icon, type IconName } from '../Icon';
2
+ import type { ButtonSize } from './ButtonBase';
3
+ import styles from './buttonIcon.module.css';
4
+
5
+ export interface ButtonIconProps {
6
+ icon: IconName;
7
+ size: ButtonSize;
8
+ }
9
+
10
+ export const ButtonIcon = ({ size, icon }: ButtonIconProps) => {
11
+ return (
12
+ <span className={styles.icon} data-size={size}>
13
+ <Icon name={icon} />
14
+ </span>
15
+ );
16
+ };
@@ -0,0 +1,16 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ButtonSize } from './ButtonBase';
3
+ import styles from './buttonLabel.module.css';
4
+
5
+ export interface ButtonLabelProps {
6
+ size: ButtonSize;
7
+ children: ReactNode;
8
+ }
9
+
10
+ export const ButtonLabel = ({ size, children }: ButtonLabelProps) => {
11
+ return (
12
+ <span className={styles.label} data-size={size}>
13
+ {children}
14
+ </span>
15
+ );
16
+ };
@@ -0,0 +1,64 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { Button, ComboButton, IconButton, MetaItem } from '../';
3
+
4
+ const meta = {
5
+ title: 'Atoms/Button/Buttons',
6
+ tags: ['autodocs'],
7
+ parameters: {},
8
+ args: {
9
+ color: 'primary',
10
+ },
11
+ argTypes: {
12
+ color: {
13
+ control: 'radio',
14
+ options: ['primary', 'secondary'],
15
+ },
16
+ },
17
+ };
18
+
19
+ export default meta;
20
+ type Story = StoryObj<typeof meta>;
21
+
22
+ const sizes = ['sm', 'md', 'lg'];
23
+ const variants = ['solid', 'outline', 'dotted', 'text'];
24
+
25
+ export const VariantsAndSizes = (args: Story) => {
26
+ return (
27
+ <div style={{ display: 'flex', flexDirection: 'column', rowGap: '1rem' }}>
28
+ {variants?.map((variant) => {
29
+ return (
30
+ <div
31
+ key={variant}
32
+ style={{
33
+ display: 'flex',
34
+ flexDirection: 'column',
35
+ rowGap: '1rem',
36
+ alignItems: 'start',
37
+ justifyContent: 'space-between',
38
+ width: '100%',
39
+ }}
40
+ >
41
+ <MetaItem>{variant}</MetaItem>
42
+ {sizes?.map((size) => {
43
+ return (
44
+ <div key={size} style={{ display: 'flex', alignItems: 'center', columnGap: '1rem' }}>
45
+ <IconButton {...args} icon="x-mark" variant={variant} size={size} />
46
+ <Button {...args} reverse variant={variant} icon="arrow-left" size={size}>
47
+ Button
48
+ </Button>
49
+ <Button {...args} variant={variant} icon="arrow-right" size={size}>
50
+ Button
51
+ </Button>
52
+ <ComboButton {...args} variant={variant} icon="chevron-down" size={size}>
53
+ ComboButton
54
+ </ComboButton>
55
+ <MetaItem>{size}</MetaItem>
56
+ </div>
57
+ );
58
+ })}
59
+ </div>
60
+ );
61
+ })}
62
+ </div>
63
+ );
64
+ };
@@ -1,7 +1,9 @@
1
1
  import cx from 'classnames';
2
2
  import type { MouseEventHandler } from 'react';
3
- import { Icon, type IconName } from '../Icon';
3
+ import type { IconName } from '../Icon';
4
4
  import { ButtonBase, type ButtonBaseProps } from './ButtonBase';
5
+ import { ButtonIcon } from './ButtonIcon';
6
+ import { ButtonLabel } from './ButtonLabel';
5
7
 
6
8
  import styles from './comboButton.module.css';
7
9
 
@@ -13,9 +15,9 @@ export interface ComboButtonProps extends Omit<ButtonBaseProps, 'onClick'> {
13
15
  }
14
16
 
15
17
  export const ComboButton = ({
16
- size = 'md',
17
18
  variant = 'solid',
18
- color,
19
+ color = 'primary',
20
+ size = 'md',
19
21
  selected = false,
20
22
  icon,
21
23
  children,
@@ -32,12 +34,12 @@ export const ComboButton = ({
32
34
  selected={selected}
33
35
  className={cx(styles.button, className)}
34
36
  >
35
- <ButtonBase size={size} onClick={onIconClick} className={styles.icon}>
36
- <Icon name={icon} />
37
+ <ButtonBase size={size} onClick={onIconClick} className={styles.secondary}>
38
+ <ButtonIcon icon={icon} size={size} />
37
39
  </ButtonBase>
38
40
  <span data-size={size} className={styles.divider} />
39
- <ButtonBase size={size} onClick={onLabelClick} className={styles.label}>
40
- {children}
41
+ <ButtonBase size={size} onClick={onLabelClick} className={styles.primary}>
42
+ <ButtonLabel size={size}>{children}</ButtonLabel>
41
43
  </ButtonBase>
42
44
  </ButtonBase>
43
45
  );
@@ -0,0 +1,47 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { MetaItem } from '../Meta';
3
+ import { IconButton } from './IconButton';
4
+
5
+ const meta = {
6
+ title: 'Atoms/Button/IconButton',
7
+ component: IconButton,
8
+ tags: ['autodocs'],
9
+ parameters: {},
10
+ args: {
11
+ children: 'IconButton',
12
+ icon: 'x-mark',
13
+ size: 'sm',
14
+ },
15
+ } satisfies Meta<typeof IconButton>;
16
+
17
+ export default meta;
18
+ type Story = StoryObj<typeof meta>;
19
+
20
+ export const Default: Story = {
21
+ args: {},
22
+ };
23
+
24
+ const sizes = ['sm', 'md', 'lg'];
25
+ const variants = ['outline', 'solid', 'dotted', 'text'];
26
+
27
+ export const Sizes = (args) => {
28
+ return (
29
+ <div style={{ display: 'flex', columnGap: '1rem', justifyContent: 'space-between', width: '100%' }}>
30
+ {variants?.map((variant) => {
31
+ return (
32
+ <div key={variant} style={{ display: 'flex', flexDirection: 'column', columnGap: '1rem' }}>
33
+ <MetaItem>{variant}</MetaItem>
34
+ {sizes?.map((size) => {
35
+ return (
36
+ <div key={size}>
37
+ <IconButton {...args} variant={variant} size={size} />
38
+ <MetaItem>{size}</MetaItem>
39
+ </div>
40
+ );
41
+ })}
42
+ </div>
43
+ );
44
+ })}
45
+ </div>
46
+ );
47
+ };
@@ -1,6 +1,9 @@
1
1
  import cx from 'classnames';
2
- import { ButtonBase, type ButtonColor, type ButtonSize, type ButtonVariant } from '../Button';
3
- import { Icon, type IconName } from '../Icon';
2
+ import type { MouseEventHandler } from 'react';
3
+ import type { IconName } from '../Icon';
4
+ import { ButtonBase } from './ButtonBase';
5
+ import type { ButtonColor, ButtonSize, ButtonVariant } from './ButtonBase';
6
+ import { ButtonIcon } from './ButtonIcon';
4
7
  import styles from './iconButton.module.css';
5
8
 
6
9
  interface IconButtonProps {
@@ -9,13 +12,20 @@ interface IconButtonProps {
9
12
  size?: ButtonSize;
10
13
  variant?: ButtonVariant;
11
14
  className?: string;
12
- onClick?: () => void;
15
+ onClick?: MouseEventHandler;
13
16
  }
14
17
 
15
- export const IconButton = ({ className, variant, color, size, icon, onClick }: IconButtonProps) => {
18
+ export const IconButton = ({
19
+ variant = 'solid',
20
+ color = 'primary',
21
+ size = 'md',
22
+ icon,
23
+ className,
24
+ onClick,
25
+ }: IconButtonProps) => {
16
26
  return (
17
27
  <ButtonBase variant={variant} color={color} size={size} className={cx(styles.button, className)} onClick={onClick}>
18
- <Icon name={icon} className={styles.icon} />
28
+ <ButtonIcon icon={icon} size={size} />
19
29
  </ButtonBase>
20
30
  );
21
31
  };
@@ -1,63 +1,22 @@
1
1
  .button {
2
2
  display: inline-flex;
3
3
  align-items: center;
4
+ column-gap: 0.125em;
5
+ border-radius: 2px;
4
6
  }
5
7
 
6
8
  .reverse {
7
9
  flex-direction: row-reverse;
8
10
  }
9
11
 
10
- .label {
11
- line-height: 1rem;
12
- font-weight: 600;
13
- }
14
-
15
- .icon {
16
- display: flex;
17
- align-items: center;
18
- justify-content: center;
19
- }
20
-
21
- /* sm 36 */
22
-
23
12
  .button[data-size="sm"] {
24
- border-radius: 2px;
25
- padding: 0 6px;
26
- }
27
-
28
- .label[data-size="sm"] {
29
- font-size: 0.875rem;
30
- padding: 9px 4px;
31
- }
32
-
33
- .icon[data-size="sm"] {
34
- font-size: 1.25rem;
13
+ padding: 0 0.375rem;
35
14
  }
36
15
 
37
- /* md 44 */
38
-
39
16
  .button[data-size="md"] {
40
- border-radius: 2px;
41
- padding: 9px 6px;
17
+ padding: 0 0.5rem;
42
18
  }
43
19
 
44
- .label[data-size="md"] {
45
- font-size: 1rem;
46
- padding: 4px 4px;
47
- }
48
-
49
- .icon[data-size="md"] {
50
- font-size: 1.5rem;
51
- }
52
-
53
- /* lg 56 */
54
-
55
20
  .button[data-size="lg"] {
56
- border-radius: 2px;
57
- padding: 9px 6px;
58
- }
59
-
60
- .label[data-size="lg"] {
61
- font-size: 1.125rem;
62
- padding: 10px;
21
+ padding: 0 0.625rem;
63
22
  }
@@ -21,7 +21,7 @@
21
21
  -moz-osx-font-smoothing: inherit;
22
22
 
23
23
  /* Corrects inability to style clickable `input` types in iOS */
24
- -webkit-appearance: none;
24
+ appearance: none;
25
25
 
26
26
  /* user select none */
27
27
  user-select: none;
@@ -45,7 +45,19 @@
45
45
  border-color: var(--theme-base-active);
46
46
  }
47
47
 
48
- /* solid */
48
+ .button[data-size="sm"] {
49
+ height: 2.25rem; /* sm 36 */
50
+ }
51
+
52
+ .button[data-size="md"] {
53
+ height: 2.75rem; /* md 44 */
54
+ }
55
+
56
+ .button[data-size="lg"] {
57
+ height: 3.5rem; /* lg 56 */
58
+ }
59
+
60
+ /* primary solid */
49
61
 
50
62
  .button[data-variant="solid"] {
51
63
  border-color: var(--theme-base-default);
@@ -53,44 +65,52 @@
53
65
  color: white;
54
66
  }
55
67
 
56
- /* outline */
68
+ .button[data-variant="solid"]:hover {
69
+ border-color: var(--theme-base-hover);
70
+ background-color: var(--theme-base-hover);
71
+ }
72
+
73
+ .button[data-variant="solid"]:active {
74
+ border-color: var(--theme-base-active);
75
+ background-color: var(--theme-base-active);
76
+ }
77
+
78
+ /* primary outline, dotted + text */
79
+
80
+ .button[data-variant="outline"],
81
+ .button[data-variant="dotted"] {
82
+ border-color: var(--theme-base-default);
83
+ }
57
84
 
58
85
  .button[data-variant="outline"] {
59
86
  border-style: solid;
60
87
  }
61
88
 
62
- /* dotted */
63
-
64
89
  .button[data-variant="dotted"] {
65
90
  border-style: dotted;
66
91
  }
67
92
 
68
- /* text */
69
-
70
93
  .button[data-variant="text"] {
71
94
  border-color: transparent;
72
95
  }
73
96
 
74
- .button[aria-selected="true"] {
75
- background-color: var(--theme-background-subtle);
76
- color: var(--theme-text-default);
97
+ .button[data-variant="outline"]:hover,
98
+ .button[data-variant="dotted"]:hover,
99
+ .button[data-variant="text"]:hover {
100
+ background-color: var(--theme-surface-default);
77
101
  }
78
102
 
79
- /* primary color */
80
-
81
- .button[data-color="primary"] {
82
- border-color: var(--theme-base-default);
103
+ .button[data-variant="outline"]:active,
104
+ .button[data-variant="dotted"]:active,
105
+ .button[data-variant="text"]:active {
106
+ background-color: var(--theme-surface-active);
83
107
  }
84
108
 
85
- .button[data-color="primary"]:hover {
86
- border-color: var(--theme-base-hover);
87
- }
109
+ /* selected */
88
110
 
89
- .button[data-color="primary"][data-variant="solid"],
90
- .button[data-color="primary"][data-variant="solid"] {
91
- border-color: var(--theme-base-default);
92
- background-color: var(--theme-base-default);
93
- color: white;
111
+ .button[aria-selected="true"] {
112
+ background-color: var(--theme-background-subtle);
113
+ color: var(--theme-text-default);
94
114
  }
95
115
 
96
116
  /* secondary color */
@@ -103,8 +123,20 @@
103
123
  border-color: var(--theme-surface-hover);
104
124
  }
105
125
 
106
- .button[data-color="secondary"][data-variant="solid"],
107
126
  .button[data-color="secondary"][data-variant="solid"] {
108
127
  border-color: var(--theme-surface-default);
109
128
  background-color: var(--theme-surface-default);
110
129
  }
130
+
131
+ .button[data-color="secondary"][data-variant="solid"]:hover {
132
+ border-color: var(--theme-surface-hover);
133
+ background-color: var(--theme-surface-hover);
134
+ }
135
+
136
+ .button[data-color="secondary"][data-variant="solid"]:active,
137
+ .button[data-color="secondary"][data-variant="outline"]:active,
138
+ .button[data-color="secondary"][data-variant="dotted"]:active,
139
+ .button[data-color="secondary"][data-variant="text"]:active {
140
+ border-color: var(--theme-surface-active);
141
+ background-color: var(--theme-surface-active);
142
+ }
@@ -0,0 +1,17 @@
1
+ .icon {
2
+ display: flex;
3
+ align-items: center;
4
+ justify-content: center;
5
+ }
6
+
7
+ .icon[data-size="sm"] {
8
+ font-size: 1.25rem;
9
+ }
10
+
11
+ .icon[data-size="md"] {
12
+ font-size: 1.5rem;
13
+ }
14
+
15
+ .icon[data-size="lg"] {
16
+ font-size: 1.625rem;
17
+ }
@@ -0,0 +1,17 @@
1
+ .label {
2
+ line-height: 1;
3
+ font-weight: 500;
4
+ padding: 0 .25em;
5
+ }
6
+
7
+ .label[data-size="sm"] {
8
+ font-size: 0.875rem;
9
+ }
10
+
11
+ .label[data-size="md"] {
12
+ font-size: 1rem;
13
+ }
14
+
15
+ .label[data-size="lg"] {
16
+ font-size: 1.125rem;
17
+ }
@@ -2,84 +2,34 @@
2
2
  display: inline-flex;
3
3
  flex-direction: row-reverse;
4
4
  align-items: center;
5
- border: 1px solid;
6
5
  border-radius: 2px;
7
6
  }
8
7
 
9
- /*
10
- .button[aria-selected="true"] {
11
- background-color: var(--theme-background-subtle);
12
- color: var(--theme-text-default);
13
- }
14
- */
15
-
16
- .label {
17
- line-height: 1rem;
18
- font-weight: 600;
19
- }
20
-
21
8
  .divider {
9
+ align-self: stretch;
22
10
  border-left: 1px solid currentColor;
23
11
  width: 1px;
24
- height: 1em;
12
+ margin: 0.375rem 0;
25
13
  }
26
14
 
27
- .icon {
28
- display: flex;
15
+ .primary,
16
+ .secondary {
17
+ display: inline-flex;
29
18
  align-items: center;
30
- justify-content: center;
31
- }
32
-
33
- /* variant */
34
-
35
- .button[data-variant="solid"] {
36
- border-color: var(--theme-base-hover);
37
- background-color: var(--theme-base-hover);
38
- color: white;
39
- }
40
-
41
- /* sm 36px */
42
-
43
- .label[data-size="sm"] {
44
- font-size: 0.875rem;
45
- padding: 8px 10px;
19
+ border: none;
46
20
  }
47
21
 
48
- .divider[data-size="sm"] {
49
- height: 20px;
50
- }
51
-
52
- .icon[data-size="sm"] {
53
- font-size: 1.25rem;
54
- padding: 6px 5px;
55
- }
56
-
57
- /* md 44px */
58
-
59
- .button[data-size="md"] {
60
- font-size: 1rem;
61
- }
62
-
63
- .label[data-size="md"] {
64
- padding: 10px;
65
- }
66
-
67
- .icon[data-size="md"] {
68
- font-size: 1.25rem;
69
- padding: 12px 8px;
70
- }
71
-
72
- /* lg 56 */
73
-
74
- .button[data-size="lg"] {
75
- font-size: 1.125rem;
22
+ .primary[data-size="sm"],
23
+ .secondary[data-size="sm"] {
24
+ padding: 0 0.375rem;
76
25
  }
77
26
 
78
- .label[data-size="lg"] {
79
- padding: 1rem;
27
+ .primary[data-size="md"],
28
+ .secondary[data-size="md"] {
29
+ padding: 0 0.5rem;
80
30
  }
81
31
 
82
- .icon[data-size="lg"] {
83
- font-size: 1.5rem;
84
- padding: 16px 10px;
32
+ .primary[data-size="lg"],
33
+ .secondary[data-size="lg"] {
34
+ padding: 0 0.625rem;
85
35
  }