@lism-css/ui 0.10.0 → 0.12.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 (209) hide show
  1. package/README.md +1 -1
  2. package/dist/components/Accordion/Accordion.stories.d.ts +7 -0
  3. package/dist/components/Accordion/getProps.d.ts +55 -42
  4. package/dist/components/Accordion/getProps.js +36 -32
  5. package/dist/components/Accordion/react/AccIcon.d.ts +2 -1
  6. package/dist/components/Accordion/react/Accordion.d.ts +12 -21
  7. package/dist/components/Accordion/react/Accordion.js +30 -29
  8. package/dist/components/Accordion/react/index.d.ts +10 -11
  9. package/dist/components/Accordion/setAccordion.d.ts +6 -3
  10. package/dist/components/Accordion/setAccordion.js +12 -10
  11. package/dist/components/Alert/Alert.stories.d.ts +13 -0
  12. package/dist/components/Alert/getProps.d.ts +6 -4
  13. package/dist/components/Alert/react/Alert.d.ts +3 -4
  14. package/dist/components/Alert/react/Alert.js +2 -2
  15. package/dist/components/Avatar/Avatar.stories.d.ts +8 -0
  16. package/dist/components/Avatar/react/Avatar.d.ts +10 -6
  17. package/dist/components/Avatar/react/Avatar.js +1 -1
  18. package/dist/components/Badge/Badge.stories.d.ts +8 -0
  19. package/dist/components/Badge/react/Badge.d.ts +3 -1
  20. package/dist/components/Badge/react/Badge.js +5 -8
  21. package/dist/components/Button/Button.stories.d.ts +8 -0
  22. package/dist/components/Button/react/Button.d.ts +3 -1
  23. package/dist/components/Button/react/Button.js +3 -6
  24. package/dist/components/Callout/Callout.stories.d.ts +12 -0
  25. package/dist/components/Callout/getProps.d.ts +3 -3
  26. package/dist/components/Callout/getProps.js +11 -12
  27. package/dist/components/Callout/react/Callout.d.ts +3 -4
  28. package/dist/components/Callout/react/Callout.js +4 -4
  29. package/dist/components/Chat/Chat.stories.d.ts +9 -0
  30. package/dist/components/Chat/getProps.d.ts +43 -44
  31. package/dist/components/Chat/getProps.js +2 -2
  32. package/dist/components/Chat/react/Chat.d.ts +11 -7
  33. package/dist/components/Chat/react/Chat.js +10 -10
  34. package/dist/components/Details/Details.stories.d.ts +6 -0
  35. package/dist/components/Details/getProps.d.ts +34 -35
  36. package/dist/components/Details/getProps.js +16 -6
  37. package/dist/components/Details/react/Details.d.ts +11 -20
  38. package/dist/components/Details/react/Details.js +15 -15
  39. package/dist/components/Details/react/index.d.ts +7 -7
  40. package/dist/components/DummyImage/DummyImage.stories.d.ts +7 -0
  41. package/dist/components/DummyText/DummyText.stories.d.ts +9 -0
  42. package/dist/components/Modal/Modal.stories.d.ts +6 -0
  43. package/dist/components/Modal/getProps.d.ts +36 -36
  44. package/dist/components/Modal/getProps.js +36 -17
  45. package/dist/components/Modal/react/Body.d.ts +2 -4
  46. package/dist/components/Modal/react/CloseBtn.d.ts +9 -7
  47. package/dist/components/Modal/react/CloseBtn.js +5 -5
  48. package/dist/components/Modal/react/Inner.d.ts +3 -4
  49. package/dist/components/Modal/react/Modal.d.ts +4 -4
  50. package/dist/components/Modal/react/Modal.js +11 -9
  51. package/dist/components/Modal/react/OpenBtn.d.ts +7 -5
  52. package/dist/components/Modal/react/OpenBtn.js +4 -4
  53. package/dist/components/Modal/react/index.d.ts +7 -8
  54. package/dist/components/NavMenu/NavMenu.stories.d.ts +7 -0
  55. package/dist/components/NavMenu/getProps.d.ts +31 -29
  56. package/dist/components/NavMenu/react/NavMenu.d.ts +6 -16
  57. package/dist/components/NavMenu/react/NavMenu.js +21 -17
  58. package/dist/components/NavMenu/react/index.d.ts +6 -6
  59. package/dist/components/ShapeDivider/ShapeDivider.stories.d.ts +10 -0
  60. package/dist/components/ShapeDivider/getProps.d.ts +16 -11
  61. package/dist/components/ShapeDivider/getProps.js +10 -12
  62. package/dist/components/ShapeDivider/react/ShapeDivider.d.ts +3 -4
  63. package/dist/components/ShapeDivider/react/ShapeDivider.js +3 -3
  64. package/dist/components/Tabs/Tabs.stories.d.ts +6 -0
  65. package/dist/components/Tabs/getProps.d.ts +11 -4
  66. package/dist/components/Tabs/getProps.js +14 -4
  67. package/dist/components/Tabs/react/Tab.d.ts +8 -6
  68. package/dist/components/Tabs/react/Tab.js +15 -6
  69. package/dist/components/Tabs/react/TabItem.d.ts +7 -4
  70. package/dist/components/Tabs/react/TabList.d.ts +2 -1
  71. package/dist/components/Tabs/react/TabPanel.d.ts +8 -6
  72. package/dist/components/Tabs/react/Tabs.d.ts +9 -7
  73. package/dist/components/Tabs/react/Tabs.js +50 -36
  74. package/dist/components/Tabs/react/index.d.ts +8 -8
  75. package/dist/components/Tabs/setTabs.d.ts +1 -1
  76. package/dist/components/Tabs/setTabs.js +25 -15
  77. package/dist/lism-css/dist/components/{Center → layout/Center}/index.js +1 -1
  78. package/dist/lism-css/dist/components/{Flex → layout/Flex}/index.js +1 -1
  79. package/dist/lism-css/dist/components/{Flow → layout/Flow}/index.js +1 -1
  80. package/dist/lism-css/dist/components/{Frame → layout/Frame}/index.js +1 -1
  81. package/dist/lism-css/dist/components/{Grid → layout/Grid}/index.js +1 -1
  82. package/dist/lism-css/dist/components/{Stack → layout/Stack}/index.js +1 -1
  83. package/dist/lism-css/dist/config/defaults/props.js +16 -26
  84. package/dist/lism-css/dist/config/defaults/states.js +3 -24
  85. package/dist/lism-css/dist/config/defaults/tokens.js +2 -2
  86. package/dist/lism-css/dist/lib/getLayoutProps.js +6 -9
  87. package/dist/lism-css/dist/lib/getLismProps.js +94 -92
  88. package/dist/lism-css/dist/lib/helper/mergeSet.js +14 -0
  89. package/dist/style.css +1 -1
  90. package/dist/ui.css +1 -1
  91. package/package.json +14 -7
  92. package/src/components/Accordion/Accordion.stories.tsx +105 -0
  93. package/src/components/Accordion/astro/Button.astro +2 -2
  94. package/src/components/Accordion/getProps.ts +91 -0
  95. package/src/components/Accordion/react/{AccIcon.jsx → AccIcon.tsx} +2 -2
  96. package/src/components/Accordion/react/{Accordion.jsx → Accordion.tsx} +33 -11
  97. package/src/components/Accordion/setAccordion.ts +120 -0
  98. package/src/components/Alert/Alert.stories.tsx +64 -0
  99. package/src/components/Alert/getProps.ts +5 -3
  100. package/src/components/Alert/react/Alert.tsx +3 -3
  101. package/src/components/Avatar/Avatar.stories.tsx +42 -0
  102. package/src/components/Avatar/react/Avatar.tsx +17 -0
  103. package/src/components/Badge/Badge.stories.tsx +40 -0
  104. package/src/components/Badge/astro/Badge.astro +1 -7
  105. package/src/components/Badge/react/Badge.tsx +7 -0
  106. package/src/components/Button/Button.stories.tsx +44 -0
  107. package/src/components/Button/astro/Button.astro +1 -7
  108. package/src/components/Button/react/Button.tsx +7 -0
  109. package/src/components/Callout/Callout.stories.tsx +55 -0
  110. package/src/components/Callout/getProps.ts +5 -5
  111. package/src/components/Callout/react/Callout.tsx +3 -3
  112. package/src/components/Chat/Chat.stories.tsx +58 -0
  113. package/src/components/Chat/_style.css +5 -5
  114. package/src/components/Chat/{getProps.js → getProps.ts} +10 -4
  115. package/src/components/Chat/react/{Chat.jsx → Chat.tsx} +13 -3
  116. package/src/components/Details/Details.stories.tsx +61 -0
  117. package/src/components/Details/astro/Title.astro +2 -2
  118. package/src/components/Details/{getProps.js → getProps.ts} +19 -6
  119. package/src/components/Details/react/Details.tsx +69 -0
  120. package/src/components/DummyImage/DummyImage.stories.tsx +23 -0
  121. package/src/components/DummyText/DummyText.stories.tsx +48 -0
  122. package/src/components/Modal/Modal.stories.tsx +67 -0
  123. package/src/components/Modal/astro/CloseBtn.astro +2 -2
  124. package/src/components/Modal/astro/OpenBtn.astro +2 -3
  125. package/src/components/Modal/getProps.ts +65 -0
  126. package/src/components/Modal/react/Body.tsx +10 -0
  127. package/src/components/Modal/react/CloseBtn.tsx +24 -0
  128. package/src/components/Modal/react/Inner.tsx +6 -0
  129. package/src/components/Modal/react/Modal.tsx +24 -0
  130. package/src/components/Modal/react/OpenBtn.tsx +15 -0
  131. package/src/components/Modal/{script.js → script.ts} +1 -1
  132. package/src/components/NavMenu/NavMenu.stories.tsx +68 -0
  133. package/src/components/NavMenu/getProps.ts +60 -0
  134. package/src/components/NavMenu/react/NavMenu.tsx +40 -0
  135. package/src/components/ShapeDivider/ShapeDivider.stories.tsx +87 -0
  136. package/src/components/ShapeDivider/getProps.ts +36 -0
  137. package/src/components/ShapeDivider/react/{ShapeDivider.jsx → ShapeDivider.tsx} +4 -4
  138. package/src/components/Tabs/Tabs.stories.tsx +79 -0
  139. package/src/components/Tabs/astro/Tab.astro +2 -1
  140. package/src/components/Tabs/astro/{transformTabitems.js → transformTabitems.ts} +9 -9
  141. package/src/components/Tabs/getProps.ts +23 -0
  142. package/src/components/Tabs/react/Tab.tsx +21 -0
  143. package/src/components/Tabs/react/TabItem.tsx +13 -0
  144. package/src/components/Tabs/react/TabList.tsx +5 -0
  145. package/src/components/Tabs/react/{TabPanel.jsx → TabPanel.tsx} +8 -3
  146. package/src/components/Tabs/react/{Tabs.jsx → Tabs.tsx} +27 -12
  147. package/src/components/Tabs/{script.js → script.ts} +2 -2
  148. package/src/components/Tabs/setTabs.ts +65 -0
  149. package/src/helper/{uuid.js → uuid.ts} +2 -2
  150. package/src/vite-env.d.ts +1 -0
  151. package/dist/components/Accordion/astro/__setEvent.d.ts +0 -1
  152. package/dist/components/Accordion/astro/index.d.ts +0 -15
  153. package/dist/components/Alert/astro/index.d.ts +0 -1
  154. package/dist/components/Callout/astro/index.d.ts +0 -1
  155. package/dist/components/Details/astro/index.d.ts +0 -13
  156. package/dist/components/DummyImage/astro/index.d.ts +0 -1
  157. package/dist/components/DummyText/astro/index.d.ts +0 -1
  158. package/dist/components/Modal/astro/index.d.ts +0 -13
  159. package/dist/components/NavMenu/astro/index.d.ts +0 -11
  160. package/dist/components/Tabs/astro/index.d.ts +0 -13
  161. package/dist/components/Tabs/astro/transformTabitems.d.ts +0 -4
  162. package/dist/components/astro.d.ts +0 -14
  163. package/dist/lism-css/dist/config/helper/getSvgUrl.js +0 -4
  164. package/src/components/Accordion/getProps.js +0 -77
  165. package/src/components/Accordion/setAccordion.js +0 -146
  166. package/src/components/Avatar/astro/index.js +0 -1
  167. package/src/components/Avatar/react/Avatar.jsx +0 -9
  168. package/src/components/Badge/astro/index.js +0 -1
  169. package/src/components/Badge/react/Badge.jsx +0 -12
  170. package/src/components/Button/astro/index.js +0 -1
  171. package/src/components/Button/react/Button.jsx +0 -12
  172. package/src/components/Chat/astro/index.js +0 -1
  173. package/src/components/Details/react/Details.jsx +0 -66
  174. package/src/components/Modal/getProps.js +0 -30
  175. package/src/components/Modal/react/Body.jsx +0 -10
  176. package/src/components/Modal/react/CloseBtn.jsx +0 -20
  177. package/src/components/Modal/react/Inner.jsx +0 -6
  178. package/src/components/Modal/react/Modal.jsx +0 -23
  179. package/src/components/Modal/react/OpenBtn.jsx +0 -11
  180. package/src/components/NavMenu/getProps.js +0 -65
  181. package/src/components/NavMenu/react/NavMenu.jsx +0 -19
  182. package/src/components/ShapeDivider/astro/index.js +0 -1
  183. package/src/components/ShapeDivider/getProps.js +0 -40
  184. package/src/components/Tabs/getProps.js +0 -8
  185. package/src/components/Tabs/react/Tab.jsx +0 -10
  186. package/src/components/Tabs/react/TabItem.jsx +0 -5
  187. package/src/components/Tabs/react/TabList.jsx +0 -6
  188. package/src/components/Tabs/setTabs.js +0 -87
  189. /package/src/components/Accordion/astro/{index.js → index.ts} +0 -0
  190. /package/src/components/Accordion/react/{index.js → index.ts} +0 -0
  191. /package/src/components/Accordion/{script.js → script.ts} +0 -0
  192. /package/{dist/components/Avatar/astro/index.d.ts → src/components/Avatar/astro/index.ts} +0 -0
  193. /package/src/components/Avatar/react/{index.js → index.ts} +0 -0
  194. /package/{dist/components/Badge/astro/index.d.ts → src/components/Badge/astro/index.ts} +0 -0
  195. /package/src/components/Badge/react/{index.js → index.ts} +0 -0
  196. /package/{dist/components/Button/astro/index.d.ts → src/components/Button/astro/index.ts} +0 -0
  197. /package/src/components/Button/react/{index.js → index.ts} +0 -0
  198. /package/{dist/components/Chat/astro/index.d.ts → src/components/Chat/astro/index.ts} +0 -0
  199. /package/src/components/Chat/react/{index.js → index.ts} +0 -0
  200. /package/src/components/Details/astro/{index.js → index.ts} +0 -0
  201. /package/src/components/Details/react/{index.js → index.ts} +0 -0
  202. /package/src/components/Modal/astro/{index.js → index.ts} +0 -0
  203. /package/src/components/Modal/react/{index.js → index.ts} +0 -0
  204. /package/src/components/NavMenu/astro/{index.js → index.ts} +0 -0
  205. /package/src/components/NavMenu/react/{index.js → index.ts} +0 -0
  206. /package/{dist/components/ShapeDivider/astro/index.d.ts → src/components/ShapeDivider/astro/index.ts} +0 -0
  207. /package/src/components/ShapeDivider/react/{index.js → index.ts} +0 -0
  208. /package/src/components/Tabs/astro/{index.js → index.ts} +0 -0
  209. /package/src/components/Tabs/react/{index.js → index.ts} +0 -0
@@ -1,21 +1,34 @@
1
1
  'use client';
2
2
  import { createContext, useRef, useId, useEffect, useContext } from 'react';
3
+ import type { ElementType } from 'react';
3
4
  import getLismProps from 'lism-css/lib/getLismProps';
4
- import { Lism, Stack } from 'lism-css/react';
5
- import { getRootProps, getItemProps, getHeadingProps, getPanelProps, defaultProps } from '../getProps';
5
+ import { Lism, Stack, type LismComponentProps } from 'lism-css/react';
6
+ import {
7
+ getRootProps,
8
+ getItemProps,
9
+ getHeadingProps,
10
+ getPanelProps,
11
+ getButtonProps,
12
+ type AccordionRootProps,
13
+ type AccordionItemProps,
14
+ type AccordionHeadingProps,
15
+ type AccordionPanelProps,
16
+ } from '../getProps';
6
17
  import { setEvent } from '../setAccordion';
7
18
  import AccIcon from './AccIcon';
8
19
 
9
20
  import '../_style.css';
10
21
 
22
+ type AccordionContextType = { accID: string } | null;
23
+
11
24
  // Context: 純粋なReact環境で AccordionItem → Button / Panel へ accID を共有
12
25
  // Astro 環境では Context が使えないため null がフォールバック
13
- const AccordionContext = createContext(null);
26
+ const AccordionContext = createContext<AccordionContextType>(null);
14
27
 
15
28
  /**
16
29
  * 複数の AccordionItem をラップするルート要素
17
30
  */
18
- export function AccordionRoot({ children, ...props }) {
31
+ export function AccordionRoot({ children, ...props }: AccordionRootProps & LismComponentProps) {
19
32
  const rootProps = getRootProps(props);
20
33
  return <Stack {...rootProps}>{children}</Stack>;
21
34
  }
@@ -23,8 +36,8 @@ export function AccordionRoot({ children, ...props }) {
23
36
  /**
24
37
  * 個別のアコーディオンアイテム(<div> ベース、setEvent で開閉イベントを登録)
25
38
  */
26
- export function AccordionItem({ children, ...props }) {
27
- const ref = useRef(null);
39
+ export function AccordionItem({ children, ...props }: AccordionItemProps & LismComponentProps) {
40
+ const ref = useRef<HTMLDivElement>(null);
28
41
 
29
42
  // コンポーネント単位でユニークIDを生成
30
43
  const accID = useId();
@@ -50,20 +63,29 @@ export function AccordionItem({ children, ...props }) {
50
63
  * 見出しエリアのラッパー(デフォルトは <div role="heading">)
51
64
  * as に h2〜h6 を指定すると role は付与されない
52
65
  */
53
- export function Heading({ children, ...props }) {
54
- return <Lism {...getHeadingProps(props)}>{children}</Lism>;
66
+ export function Heading({ children, ...props }: AccordionHeadingProps & LismComponentProps) {
67
+ const { as: headingAs, ...headingProps } = getHeadingProps(props);
68
+ return (
69
+ <Lism as={headingAs as ElementType} {...headingProps}>
70
+ {children}
71
+ </Lism>
72
+ );
55
73
  }
56
74
 
75
+ type ButtonProps<T extends ElementType = 'button'> = LismComponentProps<T> & {
76
+ accID?: string;
77
+ };
78
+
57
79
  /**
58
80
  * 開閉トリガーボタン
59
81
  * accID: Context から取得できればそれを優先、なければ props / プレースホルダー
60
82
  */
61
- export function Button({ children, accID: _accID = '__LISM_ACC_ID__', ...props }) {
83
+ export function Button<T extends ElementType = 'button'>({ children, accID: _accID = '__LISM_ACC_ID__', ...props }: ButtonProps<T>) {
62
84
  const ctx = useContext(AccordionContext);
63
85
  const accID = ctx?.accID || _accID;
64
86
 
65
87
  return (
66
- <Lism {...defaultProps.button} {...props} aria-controls={accID} aria-expanded="false">
88
+ <Lism {...(getButtonProps(props as Record<string, unknown>) as object)} aria-controls={accID} aria-expanded="false">
67
89
  {children}
68
90
  <AccIcon />
69
91
  </Lism>
@@ -73,7 +95,7 @@ export function Button({ children, accID: _accID = '__LISM_ACC_ID__', ...props }
73
95
  /**
74
96
  * パネル
75
97
  */
76
- export function Panel({ children, ...props }) {
98
+ export function Panel({ children, ...props }: AccordionPanelProps & LismComponentProps) {
77
99
  const ctx = useContext(AccordionContext);
78
100
  const { panelProps, contentProps } = getPanelProps({ _contextID: ctx?.accID, ...props });
79
101
 
@@ -0,0 +1,120 @@
1
+ import { waitFrame, waitAnimation, maybePauseAnimation } from '../../helper/animation';
2
+
3
+ // hidden を付け外しする時の値
4
+ let ACCORDION_HIDDEN_VALUE = 'until-found';
5
+
6
+ type AccordionElements = {
7
+ heading: HTMLElement;
8
+ button: HTMLButtonElement;
9
+ panel: HTMLElement;
10
+ content: HTMLElement;
11
+ };
12
+
13
+ // アコーディオン要素から必要な要素を取得
14
+ const getAccordionElements = (accordionItem: HTMLElement): AccordionElements => {
15
+ const heading = accordionItem.querySelector<HTMLElement>('.c--accordion_heading')!;
16
+ const panel = accordionItem.querySelector<HTMLElement>('.c--accordion_panel')!;
17
+ return {
18
+ heading,
19
+ button: heading.querySelector('button')!,
20
+ panel,
21
+ content: panel.querySelector<HTMLElement>('.c--accordion_content')!,
22
+ };
23
+ };
24
+
25
+ // 親に data-allow-multiple がついていなければ、展開中のアコーディオンを閉じる
26
+ const maybeCloseOpenedItems = (accordionItem: HTMLElement): void => {
27
+ const parent = accordionItem.parentNode as HTMLElement | null;
28
+ if (!parent) return;
29
+
30
+ if (parent.hasAttribute('data-allow-multiple')) return;
31
+
32
+ parent.querySelectorAll<HTMLElement>(':scope > [data-opened]').forEach((_a) => void closeAccordion(_a));
33
+ };
34
+
35
+ async function openAccordion(accordionItem: HTMLElement): Promise<void> {
36
+ const { panel, content, button } = getAccordionElements(accordionItem);
37
+
38
+ maybePauseAnimation(panel);
39
+ panel.removeAttribute('hidden');
40
+ await waitFrame();
41
+
42
+ accordionItem.style.setProperty('--_panel-h', `${content.offsetHeight}px`);
43
+ await waitFrame();
44
+
45
+ accordionItem.setAttribute('data-opened', '');
46
+ button.setAttribute('aria-expanded', 'true');
47
+
48
+ const status = await waitAnimation(panel);
49
+
50
+ if ('canceled' !== status) {
51
+ accordionItem.style.removeProperty('--_panel-h');
52
+ }
53
+ }
54
+
55
+ async function closeAccordion(accordionItem: HTMLElement): Promise<void> {
56
+ const { panel, button } = getAccordionElements(accordionItem);
57
+
58
+ maybePauseAnimation(panel);
59
+ accordionItem.style.setProperty('--_panel-h', `${panel.offsetHeight}px`);
60
+ await waitFrame();
61
+
62
+ accordionItem.removeAttribute('data-opened');
63
+ button.setAttribute('aria-expanded', 'false');
64
+ accordionItem.style.removeProperty('--_panel-h');
65
+
66
+ const status = await waitAnimation(panel);
67
+
68
+ if ('canceled' !== status) {
69
+ panel.setAttribute('hidden', ACCORDION_HIDDEN_VALUE);
70
+ }
71
+ }
72
+
73
+ function toggleAccordion(accordionItem: HTMLElement): void {
74
+ if (accordionItem.hasAttribute('data-opened')) {
75
+ void closeAccordion(accordionItem);
76
+ } else {
77
+ maybeCloseOpenedItems(accordionItem);
78
+ void openAccordion(accordionItem);
79
+ }
80
+ }
81
+
82
+ /**
83
+ * 個別のアコーディオンにイベントをセット(React用にクリーンアップ関数を返す)
84
+ */
85
+ export const setEvent = (accordionItem: HTMLElement): (() => void) => {
86
+ const { button, panel } = getAccordionElements(accordionItem);
87
+
88
+ if (panel.hasAttribute('hidden')) {
89
+ ACCORDION_HIDDEN_VALUE = panel.getAttribute('hidden') ?? 'until-found';
90
+ }
91
+
92
+ const _clickEvent = (e: Event): void => {
93
+ e.preventDefault();
94
+ toggleAccordion(accordionItem);
95
+ };
96
+
97
+ const _beforematchEvent = (e: Event): void => {
98
+ e.preventDefault();
99
+ toggleAccordion(accordionItem);
100
+ };
101
+
102
+ button.addEventListener('click', _clickEvent);
103
+ panel.addEventListener('beforematch', _beforematchEvent);
104
+
105
+ return () => {
106
+ button.removeEventListener('click', _clickEvent);
107
+ panel.removeEventListener('beforematch', _beforematchEvent);
108
+ };
109
+ };
110
+
111
+ /**
112
+ * ページ内の全アコーディオンにイベントをセット(Astro用)
113
+ */
114
+ const setAccordion = (): void => {
115
+ const accordionAll = document.querySelectorAll<HTMLElement>('.c--accordion_item');
116
+ accordionAll.forEach((accordionItem) => {
117
+ setEvent(accordionItem);
118
+ });
119
+ };
120
+ export default setAccordion;
@@ -0,0 +1,64 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import Alert from './react/Alert';
3
+ import PRESETS from './presets';
4
+
5
+ const presetTypes = Object.keys(PRESETS);
6
+
7
+ const meta: Meta<typeof Alert> = {
8
+ title: 'UI/Alert',
9
+ component: Alert,
10
+ tags: ['autodocs'],
11
+ argTypes: {
12
+ children: { control: false },
13
+ type: { control: 'select', options: presetTypes },
14
+ layout: { control: 'select', options: ['flex', 'sideMain'] },
15
+ },
16
+ };
17
+
18
+ export default meta;
19
+ type Story = StoryObj<typeof Alert>;
20
+
21
+ export const Default: Story = {
22
+ args: {
23
+ type: 'alert',
24
+ children: 'アラートのメッセージです。',
25
+ },
26
+ };
27
+
28
+ export const Point: Story = {
29
+ args: { type: 'point', children: 'ポイントのメッセージです。' },
30
+ };
31
+
32
+ export const Warning: Story = {
33
+ args: { type: 'warning', children: '警告のメッセージです。' },
34
+ };
35
+
36
+ export const Check: Story = {
37
+ args: { type: 'check', children: 'チェックのメッセージです。' },
38
+ };
39
+
40
+ export const Help: Story = {
41
+ args: { type: 'help', children: 'ヘルプのメッセージです。' },
42
+ };
43
+
44
+ export const Info: Story = {
45
+ args: { type: 'info', children: '情報のメッセージです。' },
46
+ };
47
+
48
+ export const SideMain: Story = {
49
+ name: 'layout: sideMain',
50
+ args: {
51
+ type: 'alert',
52
+ layout: 'sideMain',
53
+ children: 'サイドメインレイアウトのアラートです。',
54
+ },
55
+ };
56
+
57
+ export const CustomIcon: Story = {
58
+ name: 'カスタムアイコン',
59
+ args: {
60
+ icon: 'star',
61
+ keycolor: 'purple',
62
+ children: 'カスタムアイコンとカラー指定。',
63
+ },
64
+ };
@@ -1,17 +1,19 @@
1
1
  import PRESETS from './presets';
2
+ import type { LayoutType } from 'lism-css/lib/getLismProps';
3
+ import type { IconProps } from 'lism-css/react';
2
4
 
3
5
  export type AlertProps = {
4
6
  type?: string;
5
7
  keycolor?: string;
6
- layout?: string;
7
- icon?: string;
8
+ layout?: LayoutType;
9
+ icon?: IconProps['icon'];
8
10
  flow?: string;
9
11
  [key: string]: unknown;
10
12
  };
11
13
 
12
14
  export default function getAlertProps({ type = 'alert', keycolor, layout = 'flex', icon, flow = 's', ...props }: AlertProps) {
13
15
  const presetData = type ? PRESETS[type] : null;
14
- const _icon = icon || presetData?.icon || 'info';
16
+ const _icon = (icon || presetData?.icon || 'info') as IconProps['icon'];
15
17
  const _color = keycolor || presetData?.color || 'currentColor';
16
18
 
17
19
  return {
@@ -1,8 +1,8 @@
1
- import type { ReactNode } from 'react';
2
- import { Flow, Lism, Center, Icon } from 'lism-css/react';
1
+ import type { ElementType } from 'react';
2
+ import { Flow, Lism, Center, Icon, type LismComponentProps } from 'lism-css/react';
3
3
  import getAlertProps, { type AlertProps } from '../getProps';
4
4
 
5
- export default function Alert({ children, ...inputProps }: AlertProps & { children?: ReactNode }) {
5
+ export default function Alert<T extends ElementType = 'div'>({ children, ...inputProps }: AlertProps & LismComponentProps<T>) {
6
6
  const { icon, layout, flow, ...alertProps } = getAlertProps(inputProps);
7
7
 
8
8
  return (
@@ -0,0 +1,42 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import Avatar from './react/Avatar';
3
+
4
+ const meta: Meta<typeof Avatar> = {
5
+ title: 'UI/Avatar',
6
+ component: Avatar,
7
+ tags: ['autodocs'],
8
+ argTypes: {
9
+ src: { control: 'text' },
10
+ alt: { control: 'text' },
11
+ size: { control: 'text' },
12
+ },
13
+ };
14
+
15
+ export default meta;
16
+ type Story = StoryObj<typeof Avatar>;
17
+
18
+ export const Default: Story = {
19
+ args: {
20
+ src: 'https://cdn.lism-css.com/dummy-image.jpg',
21
+ alt: 'ユーザーアバター',
22
+ size: '4rem',
23
+ },
24
+ };
25
+
26
+ export const Small: Story = {
27
+ name: '小サイズ',
28
+ args: {
29
+ src: 'https://cdn.lism-css.com/dummy-image.jpg',
30
+ alt: '',
31
+ size: '2rem',
32
+ },
33
+ };
34
+
35
+ export const Large: Story = {
36
+ name: '大サイズ',
37
+ args: {
38
+ src: 'https://cdn.lism-css.com/dummy-image.jpg',
39
+ alt: '',
40
+ size: '8rem',
41
+ },
42
+ };
@@ -0,0 +1,17 @@
1
+ import type { ElementType } from 'react';
2
+ import { Frame, type LayoutComponentProps } from 'lism-css/react';
3
+ import type { FrameProps } from 'lism-css/lib/types/LayoutProps';
4
+
5
+ type AvatarProps<T extends ElementType = 'div'> = LayoutComponentProps<T, FrameProps> & {
6
+ size?: string;
7
+ src?: string;
8
+ alt?: string;
9
+ };
10
+
11
+ export default function Avatar<T extends ElementType = 'div'>({ size = '1.5em', src = '', alt = '', ...props }: AvatarProps<T>) {
12
+ return (
13
+ <Frame lismClass="c--avatar" ar="1/1" w={size} bdrs="99" {...(props as LayoutComponentProps<T, FrameProps>)}>
14
+ <img src={src} alt={alt} width="100%" height="100%" decoding="async" />
15
+ </Frame>
16
+ );
17
+ }
@@ -0,0 +1,40 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import Badge from './react/Badge';
3
+
4
+ const meta: Meta<typeof Badge> = {
5
+ title: 'UI/Badge',
6
+ component: Badge,
7
+ tags: ['autodocs'],
8
+ argTypes: {
9
+ children: { control: 'text' },
10
+ c: { control: 'text', description: 'テキストカラー(CSS変数キー)' },
11
+ bgc: { control: 'text', description: '背景カラー(CSS変数キー)' },
12
+ },
13
+ };
14
+
15
+ export default meta;
16
+ type Story = StoryObj<typeof Badge>;
17
+
18
+ export const Default: Story = {
19
+ args: {
20
+ children: 'Badge',
21
+ },
22
+ };
23
+
24
+ export const WithColor: Story = {
25
+ name: 'カラー指定',
26
+ args: {
27
+ children: 'New',
28
+ c: 'white',
29
+ bgc: 'red',
30
+ },
31
+ };
32
+
33
+ export const Secondary: Story = {
34
+ name: 'セカンダリカラー',
35
+ args: {
36
+ children: 'Info',
37
+ c: 'white',
38
+ bgc: 'blue',
39
+ },
40
+ };
@@ -3,14 +3,8 @@ import { Lism } from 'lism-css/astro';
3
3
  import '../_style.css';
4
4
 
5
5
  const props = Astro.props;
6
-
7
- // c--badge では c, bgc は 変数で受け取る
8
- const _propConfig = {
9
- c: { isVar: 1 },
10
- bgc: { isVar: 1 },
11
- };
12
6
  ---
13
7
 
14
- <Lism lismClass="c--badge" as="span" d="inline-flex" fz="xs" lh="xs" py="5" px="10" bdrs="10" _propConfig={_propConfig} {...props}>
8
+ <Lism lismClass="c--badge" as="span" d="inline-flex" fz="xs" lh="xs" py="5" px="10" bdrs="10" {...props}>
15
9
  <slot />
16
10
  </Lism>
@@ -0,0 +1,7 @@
1
+ import type { ElementType } from 'react';
2
+ import { Lism, type LismComponentProps } from 'lism-css/react';
3
+ import '../_style.css';
4
+
5
+ export default function Badge<T extends ElementType = 'span'>(props: LismComponentProps<T>) {
6
+ return <Lism lismClass="c--badge" as="span" d="inline-flex" fz="xs" lh="xs" py="5" px="10" bdrs="10" {...props} />;
7
+ }
@@ -0,0 +1,44 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import Button from './react/Button';
3
+
4
+ const meta: Meta<typeof Button> = {
5
+ title: 'UI/Button',
6
+ component: Button,
7
+ tags: ['autodocs'],
8
+ argTypes: {
9
+ children: { control: 'text' },
10
+ c: { control: 'text', description: 'テキストカラー(CSS変数キー)' },
11
+ bgc: { control: 'text', description: '背景カラー(CSS変数キー)' },
12
+ href: { control: 'text' },
13
+ as: { control: 'text' },
14
+ },
15
+ };
16
+
17
+ export default meta;
18
+ type Story = StoryObj<typeof Button>;
19
+
20
+ export const Default: Story = {
21
+ args: {
22
+ children: 'ボタン',
23
+ href: '#',
24
+ },
25
+ };
26
+
27
+ export const AsButton: Story = {
28
+ name: 'as="button"',
29
+ args: {
30
+ children: 'ボタン要素',
31
+ as: 'button',
32
+ },
33
+ };
34
+
35
+ export const WithColor: Story = {
36
+ name: 'カラー指定',
37
+ args: {
38
+ children: '送信する',
39
+ as: 'button',
40
+ c: 'white',
41
+ bgc: 'blue',
42
+ bdrs: '99',
43
+ },
44
+ };
@@ -3,14 +3,8 @@ import { Flex } from 'lism-css/astro';
3
3
  import '../_style.css';
4
4
 
5
5
  const props = Astro.props;
6
-
7
- // c--button では c, bgc は 変数で受け取る
8
- const _propConfig = {
9
- c: { isVar: 1 },
10
- bgc: { isVar: 1 },
11
- };
12
6
  ---
13
7
 
14
- <Flex lismClass="c--button" as="a" lh="s" py="10" px="20" hov="o" _propConfig={_propConfig} {...props}>
8
+ <Flex lismClass="c--button" as="a" lh="s" py="10" px="20" hov="o" {...props}>
15
9
  <slot />
16
10
  </Flex>
@@ -0,0 +1,7 @@
1
+ import type { ElementType } from 'react';
2
+ import { Flex, type LismComponentProps } from 'lism-css/react';
3
+ import '../_style.css';
4
+
5
+ export default function Button<T extends ElementType = 'a'>(props: LismComponentProps<T>) {
6
+ return <Flex lismClass="c--button" as="a" lh="s" py="10" px="20" hov="o" {...props} />;
7
+ }
@@ -0,0 +1,55 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import Callout from './react/Callout';
3
+ import PRESETS from './presets';
4
+
5
+ const presetTypes = Object.keys(PRESETS);
6
+
7
+ const meta: Meta<typeof Callout> = {
8
+ title: 'UI/Callout',
9
+ component: Callout,
10
+ tags: ['autodocs'],
11
+ argTypes: {
12
+ children: { control: false },
13
+ type: { control: 'select', options: presetTypes },
14
+ title: { control: 'text' },
15
+ },
16
+ };
17
+
18
+ export default meta;
19
+ type Story = StoryObj<typeof Callout>;
20
+
21
+ export const Default: Story = {
22
+ args: {
23
+ type: 'note',
24
+ children: 'コールアウトのメッセージです。',
25
+ },
26
+ };
27
+
28
+ export const WithTitle: Story = {
29
+ name: 'タイトルあり',
30
+ args: {
31
+ type: 'note',
32
+ title: 'メモ',
33
+ children: 'タイトル付きのコールアウトです。',
34
+ },
35
+ };
36
+
37
+ export const Alert: Story = {
38
+ args: { type: 'alert', title: '警告', children: '警告のメッセージです。' },
39
+ };
40
+
41
+ export const Point: Story = {
42
+ args: { type: 'point', title: 'ポイント', children: 'ポイントのメッセージです。' },
43
+ };
44
+
45
+ export const Warning: Story = {
46
+ args: { type: 'warning', title: '注意', children: '注意のメッセージです。' },
47
+ };
48
+
49
+ export const Check: Story = {
50
+ args: { type: 'check', title: 'OK', children: 'チェックのメッセージです。' },
51
+ };
52
+
53
+ export const Help: Story = {
54
+ args: { type: 'help', title: 'ヘルプ', children: 'ヘルプのメッセージです。' },
55
+ };
@@ -1,9 +1,10 @@
1
1
  import PRESETS from './presets';
2
+ import type { IconProps } from 'lism-css/react';
2
3
 
3
4
  export type CalloutProps = {
4
5
  type?: string;
5
6
  keycolor?: string;
6
- icon?: string;
7
+ icon?: IconProps['icon'];
7
8
  title?: string;
8
9
  flow?: string;
9
10
  [key: string]: unknown;
@@ -11,22 +12,21 @@ export type CalloutProps = {
11
12
 
12
13
  export default function getCalloutProps({ type = 'note', keycolor, icon, title, flow = 's', ...props }: CalloutProps) {
13
14
  const presetData = type ? PRESETS[type] : null;
14
- const _icon = icon || presetData?.icon || 'note';
15
+ const _icon = (icon || presetData?.icon || 'note') as IconProps['icon'];
15
16
  const _keycolor = keycolor || presetData?.color || null;
16
17
 
17
18
  return {
18
19
  icon: _icon,
19
20
  title,
20
21
  flow,
21
- lismClass: 'c--callout u--cbox',
22
+ lismClass: 'c--callout u--cbox set--shadow',
22
23
  keycolor: _keycolor,
23
24
  p: '20',
24
25
  g: '10',
25
26
  bdc: 'keycolor',
26
27
  'bd-x-s': '-',
27
- bdw: '4px',
28
+ bdw: '3px',
28
29
  bxsh: '10',
29
- bdrs: '5',
30
30
  ...props,
31
31
  };
32
32
  }
@@ -1,8 +1,8 @@
1
- import type { ReactNode } from 'react';
2
- import { Flow, Flex, Stack, Icon, Center } from 'lism-css/react';
1
+ import type { ElementType } from 'react';
2
+ import { Flow, Flex, Stack, Icon, Center, type LismComponentProps } from 'lism-css/react';
3
3
  import getCalloutProps, { type CalloutProps } from '../getProps';
4
4
 
5
- export default function Callout({ children, ...inputProps }: CalloutProps & { children?: ReactNode }) {
5
+ export default function Callout<T extends ElementType = 'div'>({ children, ...inputProps }: CalloutProps & LismComponentProps<T>) {
6
6
  const { icon, title, flow, ...calloutProps } = getCalloutProps(inputProps);
7
7
 
8
8
  return (
@@ -0,0 +1,58 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import Chat from './react/Chat';
3
+
4
+ const meta: Meta<typeof Chat> = {
5
+ title: 'UI/Chat',
6
+ component: Chat,
7
+ tags: ['autodocs'],
8
+ argTypes: {
9
+ children: { control: false },
10
+ name: { control: 'text' },
11
+ avatar: { control: 'text' },
12
+ direction: { control: 'select', options: ['start', 'end'] },
13
+ variant: { control: 'select', options: ['speak', 'think'] },
14
+ keycolor: { control: 'text' },
15
+ },
16
+ };
17
+
18
+ export default meta;
19
+ type Story = StoryObj<typeof Chat>;
20
+
21
+ const AVATAR_SRC = 'https://cdn.lism-css.com/dummy-image.jpg';
22
+
23
+ export const Default: Story = {
24
+ args: {
25
+ name: 'ユーザー',
26
+ avatar: AVATAR_SRC,
27
+ children: 'こんにちは!チャットコンポーネントのデモです。',
28
+ },
29
+ };
30
+
31
+ export const End: Story = {
32
+ name: 'direction: end(右寄せ)',
33
+ args: {
34
+ name: '自分',
35
+ avatar: AVATAR_SRC,
36
+ direction: 'end',
37
+ keycolor: 'blue',
38
+ children: '右寄せのチャットメッセージです。',
39
+ },
40
+ };
41
+
42
+ export const NoAvatar: Story = {
43
+ name: 'アバターなし',
44
+ args: {
45
+ name: 'ゲスト',
46
+ children: 'アバターなしのチャットです。',
47
+ },
48
+ };
49
+
50
+ export const Think: Story = {
51
+ name: 'variant: think',
52
+ args: {
53
+ name: 'キャラ',
54
+ avatar: AVATAR_SRC,
55
+ variant: 'think',
56
+ children: '考え中のバリアントです。',
57
+ },
58
+ };