@lism-css/ui 0.9.2 → 0.10.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 (189) hide show
  1. package/README.ja.md +137 -0
  2. package/README.md +93 -5
  3. package/dist/components/Accordion/getProps.js +53 -0
  4. package/dist/components/Accordion/react/AccIcon.js +9 -0
  5. package/dist/components/Accordion/react/Accordion.d.ts +5 -6
  6. package/dist/components/Accordion/react/Accordion.js +45 -0
  7. package/dist/components/Accordion/react/index.js +6 -0
  8. package/dist/components/Alert/getProps.js +20 -0
  9. package/dist/components/Alert/presets.js +29 -0
  10. package/dist/components/Alert/react/Alert.js +16 -0
  11. package/dist/components/Avatar/react/Avatar.js +8 -0
  12. package/dist/components/Badge/react/Badge.js +12 -0
  13. package/dist/components/Button/react/Button.js +12 -0
  14. package/dist/components/Callout/getProps.js +22 -0
  15. package/dist/components/Callout/presets.js +29 -0
  16. package/dist/components/Callout/react/Callout.js +20 -0
  17. package/dist/components/Chat/getProps.js +47 -0
  18. package/dist/components/Chat/react/Chat.js +22 -0
  19. package/dist/components/Details/getProps.js +15 -0
  20. package/dist/components/Details/react/Details.js +28 -0
  21. package/dist/components/Details/react/index.js +5 -0
  22. package/dist/components/DummyImage/astro/index.d.ts +1 -0
  23. package/dist/components/DummyImage/react/DummyImage.d.ts +2 -0
  24. package/dist/components/DummyImage/react/DummyImage.js +8 -0
  25. package/dist/components/DummyImage/react/index.d.ts +1 -0
  26. package/dist/components/DummyText/astro/index.d.ts +1 -0
  27. package/dist/components/DummyText/getContent.d.ts +11 -0
  28. package/dist/components/DummyText/getContent.js +9 -0
  29. package/dist/components/DummyText/react/DummyText.d.ts +10 -0
  30. package/dist/components/DummyText/react/DummyText.js +10 -0
  31. package/dist/components/DummyText/react/index.d.ts +1 -0
  32. package/dist/components/DummyText/texts.d.ts +22 -0
  33. package/dist/components/DummyText/texts.js +39 -0
  34. package/dist/components/Modal/getProps.js +25 -0
  35. package/dist/components/Modal/react/Body.js +9 -0
  36. package/dist/components/Modal/react/CloseBtn.js +13 -0
  37. package/dist/components/Modal/react/Inner.js +9 -0
  38. package/dist/components/Modal/react/Modal.d.ts +1 -2
  39. package/dist/components/Modal/react/Modal.js +17 -0
  40. package/dist/components/Modal/react/OpenBtn.js +9 -0
  41. package/dist/components/Modal/react/index.js +9 -0
  42. package/dist/components/Modal/setModal.js +16 -17
  43. package/dist/components/NavMenu/getProps.js +40 -0
  44. package/dist/components/NavMenu/react/NavMenu.js +24 -0
  45. package/dist/components/NavMenu/react/index.js +5 -0
  46. package/dist/components/ShapeDivider/getProps.js +22 -0
  47. package/dist/components/ShapeDivider/react/ShapeDivider.js +26 -0
  48. package/dist/components/Tabs/getProps.js +10 -0
  49. package/dist/components/Tabs/react/Tab.js +9 -0
  50. package/dist/components/Tabs/react/TabItem.js +7 -0
  51. package/dist/components/Tabs/react/TabList.js +8 -0
  52. package/dist/components/Tabs/react/TabPanel.js +9 -0
  53. package/dist/components/Tabs/react/Tabs.d.ts +1 -2
  54. package/dist/components/Tabs/react/Tabs.js +48 -0
  55. package/dist/components/Tabs/react/index.js +9 -0
  56. package/dist/components/Tabs/setTabs.js +10 -11
  57. package/dist/components/astro.d.ts +2 -0
  58. package/dist/components/react.d.ts +2 -0
  59. package/dist/components/react.js +30 -0
  60. package/dist/lism-css/dist/components/Center/index.js +8 -0
  61. package/dist/lism-css/dist/components/Flex/index.js +8 -0
  62. package/dist/lism-css/dist/components/Flow/index.js +8 -0
  63. package/dist/lism-css/dist/components/Frame/index.js +8 -0
  64. package/dist/lism-css/dist/components/Grid/index.js +8 -0
  65. package/dist/lism-css/dist/components/Lism/index.js +8 -0
  66. package/dist/lism-css/dist/components/Stack/index.js +8 -0
  67. package/dist/lism-css/dist/components/atomic/Decorator/getProps.js +15 -0
  68. package/dist/lism-css/dist/components/atomic/Decorator/index.js +9 -0
  69. package/dist/lism-css/dist/components/atomic/Icon/SVG.js +22 -0
  70. package/dist/lism-css/dist/components/atomic/Icon/getProps.js +56 -0
  71. package/dist/lism-css/dist/components/atomic/Icon/index.js +12 -0
  72. package/dist/lism-css/dist/components/atomic/Icon/presets.js +276 -0
  73. package/dist/lism-css/dist/config/default-config.js +11 -0
  74. package/dist/lism-css/dist/config/defaults/props.js +340 -0
  75. package/dist/lism-css/dist/config/defaults/states.js +39 -0
  76. package/dist/lism-css/dist/config/defaults/tokens.js +30 -0
  77. package/dist/lism-css/dist/config/helper/getSvgUrl.js +4 -0
  78. package/dist/lism-css/dist/config/helper.js +27 -0
  79. package/dist/lism-css/dist/config/index.js +17 -0
  80. package/dist/lism-css/dist/lib/getBpData.js +19 -0
  81. package/dist/lism-css/dist/lib/getLayoutProps.js +30 -0
  82. package/dist/lism-css/dist/lib/getLismProps.js +188 -0
  83. package/dist/lism-css/dist/lib/getMaybeCssVar.js +42 -0
  84. package/dist/lism-css/dist/lib/getMaybeTokenValue.js +26 -0
  85. package/dist/lism-css/dist/lib/getUtilKey.js +13 -0
  86. package/dist/lism-css/dist/lib/helper/atts.js +11 -0
  87. package/dist/lism-css/dist/lib/helper/filterEmptyObj.js +10 -0
  88. package/dist/lism-css/dist/lib/helper/hasSomeKeys.js +6 -0
  89. package/dist/lism-css/dist/lib/helper/isEmptyObj.js +6 -0
  90. package/dist/lism-css/dist/lib/helper/isNumStr.js +6 -0
  91. package/dist/lism-css/dist/lib/helper/splitWithComma.js +6 -0
  92. package/dist/lism-css/dist/lib/isPresetValue.js +13 -0
  93. package/dist/lism-css/dist/lib/isTokenValue.js +27 -0
  94. package/dist/style.css +1 -1
  95. package/dist/ui.css +1 -0
  96. package/package.json +9 -7
  97. package/src/components/Accordion/_style.css +69 -69
  98. package/src/components/Accordion/astro/Button.astro +2 -2
  99. package/src/components/Accordion/astro/Heading.astro +1 -1
  100. package/src/components/Accordion/astro/Item.astro +7 -7
  101. package/src/components/Accordion/astro/Panel.astro +3 -3
  102. package/src/components/Accordion/astro/Root.astro +3 -3
  103. package/src/components/Accordion/getProps.js +54 -54
  104. package/src/components/Accordion/react/AccIcon.jsx +1 -1
  105. package/src/components/Accordion/react/Accordion.jsx +37 -36
  106. package/src/components/Accordion/script.js +1 -1
  107. package/src/components/Accordion/setAccordion.js +93 -93
  108. package/src/components/Alert/astro/Alert.astro +6 -6
  109. package/src/components/Alert/getProps.ts +22 -22
  110. package/src/components/Alert/presets.ts +26 -26
  111. package/src/components/Alert/react/Alert.tsx +9 -9
  112. package/src/components/Avatar/astro/Avatar.astro +2 -2
  113. package/src/components/Avatar/react/Avatar.jsx +5 -5
  114. package/src/components/Badge/_style.css +14 -14
  115. package/src/components/Badge/astro/Badge.astro +4 -4
  116. package/src/components/Badge/react/Badge.jsx +6 -6
  117. package/src/components/Button/_style.css +29 -29
  118. package/src/components/Button/astro/Button.astro +4 -4
  119. package/src/components/Button/react/Button.jsx +6 -6
  120. package/src/components/Callout/astro/Callout.astro +13 -13
  121. package/src/components/Callout/getProps.ts +24 -24
  122. package/src/components/Callout/presets.ts +26 -26
  123. package/src/components/Callout/react/Callout.tsx +16 -16
  124. package/src/components/Chat/_style.css +49 -49
  125. package/src/components/Chat/astro/Chat.astro +27 -27
  126. package/src/components/Chat/getProps.js +40 -45
  127. package/src/components/Chat/react/Chat.jsx +17 -17
  128. package/src/components/Details/_style.css +39 -39
  129. package/src/components/Details/astro/Content.astro +3 -3
  130. package/src/components/Details/astro/Details.astro +1 -1
  131. package/src/components/Details/astro/Icon.astro +1 -1
  132. package/src/components/Details/astro/Summary.astro +2 -2
  133. package/src/components/Details/astro/Title.astro +1 -1
  134. package/src/components/Details/getProps.js +7 -7
  135. package/src/components/Details/react/Details.jsx +24 -24
  136. package/src/components/DummyImage/astro/DummyImage.astro +7 -0
  137. package/src/components/DummyImage/astro/index.ts +1 -0
  138. package/src/components/DummyImage/react/DummyImage.tsx +5 -0
  139. package/src/components/DummyImage/react/index.ts +1 -0
  140. package/src/components/DummyText/astro/DummyText.astro +9 -0
  141. package/src/components/DummyText/astro/index.ts +1 -0
  142. package/src/components/DummyText/getContent.ts +39 -0
  143. package/src/components/DummyText/react/DummyText.tsx +15 -0
  144. package/src/components/DummyText/react/index.ts +1 -0
  145. package/src/components/DummyText/texts.ts +39 -0
  146. package/src/components/Modal/_style.css +34 -34
  147. package/src/components/Modal/astro/Body.astro +1 -1
  148. package/src/components/Modal/astro/CloseBtn.astro +10 -10
  149. package/src/components/Modal/astro/Inner.astro +1 -1
  150. package/src/components/Modal/astro/Modal.astro +3 -3
  151. package/src/components/Modal/astro/OpenBtn.astro +1 -1
  152. package/src/components/Modal/getProps.js +19 -19
  153. package/src/components/Modal/react/Body.jsx +5 -5
  154. package/src/components/Modal/react/CloseBtn.jsx +13 -13
  155. package/src/components/Modal/react/Inner.jsx +1 -1
  156. package/src/components/Modal/react/Modal.jsx +12 -11
  157. package/src/components/Modal/react/OpenBtn.jsx +5 -5
  158. package/src/components/Modal/script.js +1 -1
  159. package/src/components/Modal/setModal.ts +92 -92
  160. package/src/components/NavMenu/_style.css +17 -17
  161. package/src/components/NavMenu/astro/Item.astro +1 -1
  162. package/src/components/NavMenu/astro/Link.astro +1 -1
  163. package/src/components/NavMenu/astro/Nest.astro +1 -1
  164. package/src/components/NavMenu/astro/Root.astro +1 -1
  165. package/src/components/NavMenu/getProps.js +28 -28
  166. package/src/components/NavMenu/react/NavMenu.jsx +4 -4
  167. package/src/components/ShapeDivider/_style.css +51 -51
  168. package/src/components/ShapeDivider/astro/ShapeDivider.astro +20 -20
  169. package/src/components/ShapeDivider/getProps.js +23 -23
  170. package/src/components/ShapeDivider/react/ShapeDivider.jsx +24 -24
  171. package/src/components/Tabs/_style.css +29 -29
  172. package/src/components/Tabs/astro/Tab.astro +2 -2
  173. package/src/components/Tabs/astro/TabItem.astro +1 -1
  174. package/src/components/Tabs/astro/TabList.astro +2 -2
  175. package/src/components/Tabs/astro/TabPanel.astro +2 -2
  176. package/src/components/Tabs/astro/Tabs.astro +20 -20
  177. package/src/components/Tabs/astro/transformTabitems.js +30 -30
  178. package/src/components/Tabs/getProps.js +4 -4
  179. package/src/components/Tabs/react/Tab.jsx +4 -12
  180. package/src/components/Tabs/react/TabItem.jsx +1 -1
  181. package/src/components/Tabs/react/TabList.jsx +2 -2
  182. package/src/components/Tabs/react/TabPanel.jsx +2 -2
  183. package/src/components/Tabs/react/Tabs.jsx +46 -47
  184. package/src/components/Tabs/script.js +4 -4
  185. package/src/components/Tabs/setTabs.js +70 -70
  186. package/src/components/astro.ts +2 -0
  187. package/src/components/react.ts +2 -0
  188. package/src/helper/animation.ts +10 -10
  189. package/src/helper/uuid.js +3 -3
@@ -8,10 +8,10 @@ const rootProps = getRootProps(Astro.props || {});
8
8
  ---
9
9
 
10
10
  <Stack {...rootProps}>
11
- <slot />
11
+ <slot />
12
12
  </Stack>
13
13
 
14
14
  <script>
15
- import setAccordion from '../setAccordion';
16
- setAccordion();
15
+ import setAccordion from '../setAccordion';
16
+ setAccordion();
17
17
  </script>
@@ -1,77 +1,77 @@
1
1
  import atts from 'lism-css/lib/helper/atts';
2
2
 
3
3
  export function getRootProps({ lismClass, allowMultiple, ...props }) {
4
- props.lismClass = atts(lismClass, 'c--accordion');
5
- if (allowMultiple) props['data-allow-multiple'] = '';
6
- return props;
4
+ props.lismClass = atts(lismClass, 'c--accordion');
5
+ if (allowMultiple) props['data-allow-multiple'] = '';
6
+ return props;
7
7
  }
8
8
 
9
9
  // duration: [s]
10
10
  export function getItemProps({ lismClass, ...props }) {
11
- props.lismClass = atts(lismClass, 'c--accordion_item');
12
- return props;
11
+ props.lismClass = atts(lismClass, 'c--accordion_item');
12
+ return props;
13
13
  }
14
14
 
15
15
  export function getHeadingProps(props) {
16
- const defaultProps = {
17
- lismClass: 'c--accordion_heading',
18
- as: 'div',
19
- setPlain: 1,
20
- };
16
+ const defaultProps = {
17
+ lismClass: 'c--accordion_heading',
18
+ as: 'div',
19
+ setPlain: 1,
20
+ };
21
21
 
22
- const returnProps = { ...defaultProps, ...props };
22
+ const returnProps = { ...defaultProps, ...props };
23
23
 
24
- // div の時は role 付与
25
- if (returnProps.as === 'div') {
26
- returnProps.role = 'heading';
27
- }
28
- return returnProps;
24
+ // div の時は role 付与
25
+ if (returnProps.as === 'div') {
26
+ returnProps.role = 'heading';
27
+ }
28
+ return returnProps;
29
29
  }
30
30
 
31
31
  // id: Context から取得できればそれを優先(React用)
32
32
  export function getPanelProps({ lismClass, _contextID, accID = '__LISM_ACC_ID__', isOpen = false, ...props }) {
33
- // panel側は必要最低限のプロパティのみ。
34
- const panelProps = {
35
- lismClass: atts(lismClass, 'c--accordion_panel'),
36
- id: _contextID || accID,
37
- hidden: isOpen ? undefined : 'until-found',
38
- pos: 'relative',
39
- ov: 'hidden',
40
- };
33
+ // panel側は必要最低限のプロパティのみ。
34
+ const panelProps = {
35
+ lismClass: atts(lismClass, 'c--accordion_panel'),
36
+ id: _contextID || accID,
37
+ hidden: isOpen ? undefined : 'until-found',
38
+ pos: 'relative',
39
+ ov: 'hidden',
40
+ };
41
41
 
42
- // 余白などその他の指定は全て _content 側へ渡す
43
- const contentProps = { lismClass: 'c--accordion_content', layout: 'flow', ...props };
42
+ // 余白などその他の指定は全て _content 側へ渡す
43
+ const contentProps = { lismClass: 'c--accordion_content', layout: 'flow', ...props };
44
44
 
45
- // content側へ移すprops
46
- // ['p', 'px', 'py', 'pl', 'pr', 'pt', 'pb', 'px-s', 'px-e', 'py-s', 'py-e'].forEach((prop) => {
47
- // if (props[prop]) {
48
- // contentProps[prop] = props[prop];
49
- // delete props[prop];
50
- // }
51
- // });
45
+ // content側へ移すprops
46
+ // ['p', 'px', 'py', 'pl', 'pr', 'pt', 'pb', 'px-s', 'px-e', 'py-s', 'py-e'].forEach((prop) => {
47
+ // if (props[prop]) {
48
+ // contentProps[prop] = props[prop];
49
+ // delete props[prop];
50
+ // }
51
+ // });
52
52
 
53
- // 2つ返す
54
- return { panelProps, contentProps };
53
+ // 2つ返す
54
+ return { panelProps, contentProps };
55
55
  }
56
56
 
57
57
  export const defaultProps = {
58
- // header: { lismClass: 'c--accordion_header' },
59
- button: {
60
- lismClass: 'c--accordion_button',
61
- as: 'button',
62
- layout: 'flex',
63
- setPlain: 1,
64
- g: '10',
65
- w: '100%',
66
- ai: 'center',
67
- jc: 'between',
68
- },
69
- icon: {
70
- lismClass: 'c--accordion_icon a--icon',
71
- as: 'span',
72
- // d: 'grid',
73
- pi: 'center',
74
- fxsh: '0',
75
- 'aria-hidden': 'true',
76
- },
58
+ // header: { lismClass: 'c--accordion_header' },
59
+ button: {
60
+ lismClass: 'c--accordion_button',
61
+ as: 'button',
62
+ layout: 'flex',
63
+ setPlain: 1,
64
+ g: '10',
65
+ w: '100%',
66
+ ai: 'center',
67
+ jc: 'between',
68
+ },
69
+ icon: {
70
+ lismClass: 'c--accordion_icon a--icon',
71
+ as: 'span',
72
+ // d: 'grid',
73
+ pi: 'center',
74
+ fxsh: '0',
75
+ 'aria-hidden': 'true',
76
+ },
77
77
  };
@@ -3,5 +3,5 @@ import { defaultProps } from '../getProps';
3
3
 
4
4
  // CSS疑似要素(::before / ::after)でアイコンを描画するコンポーネント
5
5
  export default function AccIcon(props) {
6
- return <Lism {...defaultProps.icon} {...props} />;
6
+ return <Lism {...defaultProps.icon} {...props} />;
7
7
  }
@@ -1,4 +1,5 @@
1
- import React from 'react';
1
+ 'use client';
2
+ import { createContext, useRef, useId, useEffect, useContext } from 'react';
2
3
  import getLismProps from 'lism-css/lib/getLismProps';
3
4
  import { Lism, Stack } from 'lism-css/react';
4
5
  import { getRootProps, getItemProps, getHeadingProps, getPanelProps, defaultProps } from '../getProps';
@@ -9,40 +10,40 @@ import '../_style.css';
9
10
 
10
11
  // Context: 純粋なReact環境で AccordionItem → Button / Panel へ accID を共有
11
12
  // Astro 環境では Context が使えないため null がフォールバック
12
- const AccordionContext = React.createContext(null);
13
+ const AccordionContext = createContext(null);
13
14
 
14
15
  /**
15
16
  * 複数の AccordionItem をラップするルート要素
16
17
  */
17
18
  export function AccordionRoot({ children, ...props }) {
18
- const rootProps = getRootProps(props);
19
- return <Stack {...rootProps}>{children}</Stack>;
19
+ const rootProps = getRootProps(props);
20
+ return <Stack {...rootProps}>{children}</Stack>;
20
21
  }
21
22
 
22
23
  /**
23
24
  * 個別のアコーディオンアイテム(<div> ベース、setEvent で開閉イベントを登録)
24
25
  */
25
26
  export function AccordionItem({ children, ...props }) {
26
- const ref = React.useRef(null);
27
+ const ref = useRef(null);
27
28
 
28
- // コンポーネント単位でユニークIDを生成
29
- const accID = React.useId();
29
+ // コンポーネント単位でユニークIDを生成
30
+ const accID = useId();
30
31
 
31
- // マウント時に開閉イベントを登録(アンマウント時にクリーンアップ)
32
- React.useEffect(() => {
33
- if (!ref.current) return;
34
- return setEvent(ref.current);
35
- }, []);
32
+ // マウント時に開閉イベントを登録(アンマウント時にクリーンアップ)
33
+ useEffect(() => {
34
+ if (!ref.current) return;
35
+ return setEvent(ref.current);
36
+ }, []);
36
37
 
37
- const lismProps = getLismProps(getItemProps(props));
38
+ const lismProps = getLismProps(getItemProps(props));
38
39
 
39
- return (
40
- <AccordionContext.Provider value={{ accID }}>
41
- <div ref={ref} {...lismProps}>
42
- {children}
43
- </div>
44
- </AccordionContext.Provider>
45
- );
40
+ return (
41
+ <AccordionContext.Provider value={{ accID }}>
42
+ <div ref={ref} {...lismProps}>
43
+ {children}
44
+ </div>
45
+ </AccordionContext.Provider>
46
+ );
46
47
  }
47
48
 
48
49
  /**
@@ -50,7 +51,7 @@ export function AccordionItem({ children, ...props }) {
50
51
  * as に h2〜h6 を指定すると role は付与されない
51
52
  */
52
53
  export function Heading({ children, ...props }) {
53
- return <Lism {...getHeadingProps(props)}>{children}</Lism>;
54
+ return <Lism {...getHeadingProps(props)}>{children}</Lism>;
54
55
  }
55
56
 
56
57
  /**
@@ -58,27 +59,27 @@ export function Heading({ children, ...props }) {
58
59
  * accID: Context から取得できればそれを優先、なければ props / プレースホルダー
59
60
  */
60
61
  export function Button({ children, accID: _accID = '__LISM_ACC_ID__', ...props }) {
61
- const ctx = React.useContext(AccordionContext);
62
- const accID = ctx?.accID || _accID;
62
+ const ctx = useContext(AccordionContext);
63
+ const accID = ctx?.accID || _accID;
63
64
 
64
- return (
65
- <Lism {...defaultProps.button} {...props} aria-controls={accID} aria-expanded='false'>
66
- {children}
67
- <AccIcon />
68
- </Lism>
69
- );
65
+ return (
66
+ <Lism {...defaultProps.button} {...props} aria-controls={accID} aria-expanded="false">
67
+ {children}
68
+ <AccIcon />
69
+ </Lism>
70
+ );
70
71
  }
71
72
 
72
73
  /**
73
74
  * パネル
74
75
  */
75
76
  export function Panel({ children, ...props }) {
76
- const ctx = React.useContext(AccordionContext);
77
- const { panelProps, contentProps } = getPanelProps({ _contextID: ctx?.accID, ...props });
77
+ const ctx = useContext(AccordionContext);
78
+ const { panelProps, contentProps } = getPanelProps({ _contextID: ctx?.accID, ...props });
78
79
 
79
- return (
80
- <Lism {...panelProps}>
81
- <Lism {...contentProps}>{children}</Lism>
82
- </Lism>
83
- );
80
+ return (
81
+ <Lism {...panelProps}>
82
+ <Lism {...contentProps}>{children}</Lism>
83
+ </Lism>
84
+ );
84
85
  }
@@ -1,5 +1,5 @@
1
1
  import setAccordion from './setAccordion.js';
2
2
 
3
3
  document.addEventListener('DOMContentLoaded', function () {
4
- setAccordion();
4
+ setAccordion();
5
5
  });
@@ -5,142 +5,142 @@ let ACCORDION_HIDDEN_VALUE = 'until-found';
5
5
 
6
6
  // アコーディオン要素から必要な要素を取得
7
7
  const getAccordionElements = (accordionItem) => {
8
- const heading = accordionItem.querySelector('.c--accordion_heading');
9
- const panel = accordionItem.querySelector('.c--accordion_panel');
10
- return {
11
- heading,
12
- button: heading.querySelector('button'),
13
- panel,
14
- content: panel.querySelector('.c--accordion_content'),
15
- };
8
+ const heading = accordionItem.querySelector('.c--accordion_heading');
9
+ const panel = accordionItem.querySelector('.c--accordion_panel');
10
+ return {
11
+ heading,
12
+ button: heading.querySelector('button'),
13
+ panel,
14
+ content: panel.querySelector('.c--accordion_content'),
15
+ };
16
16
  };
17
17
 
18
18
  // 親に data-allow-multiple がついていなければ、展開中のアコーディオンを閉じる
19
19
  // Memo: 自身の除外処理はしていない( 開く動作の前に呼び出す & もし自分が含まれていても連打可能なため )
20
20
  const maybeCloseOpenedItems = (accordionItem) => {
21
- const parent = accordionItem.parentNode;
22
- if (!parent) return;
21
+ const parent = accordionItem.parentNode;
22
+ if (!parent) return;
23
23
 
24
- // 親の data-allow-multiple 属性の有無をチェック
25
- if (parent.hasAttribute('data-allow-multiple')) return;
24
+ // 親の data-allow-multiple 属性の有無をチェック
25
+ if (parent.hasAttribute('data-allow-multiple')) return;
26
26
 
27
- // 開いているアコーディオンを取得して閉じる
28
- parent.querySelectorAll(':scope > [data-opened]').forEach((_a) => closeAccordion(_a));
27
+ // 開いているアコーディオンを取得して閉じる
28
+ parent.querySelectorAll(':scope > [data-opened]').forEach((_a) => closeAccordion(_a));
29
29
  };
30
30
 
31
31
  async function openAccordion(accordionItem) {
32
- const { panel, content, button } = getAccordionElements(accordionItem);
32
+ const { panel, content, button } = getAccordionElements(accordionItem);
33
33
 
34
- // アニメーションがあれば一時停止
35
- maybePauseAnimation(panel);
34
+ // アニメーションがあれば一時停止
35
+ maybePauseAnimation(panel);
36
36
 
37
- // hidden を削除
38
- panel.removeAttribute('hidden');
37
+ // hidden を削除
38
+ panel.removeAttribute('hidden');
39
39
 
40
- // 1フレーム待機
41
- await waitFrame();
40
+ // 1フレーム待機
41
+ await waitFrame();
42
42
 
43
- // 次フレームで高さセット( 目標の高さ = content の高さ )
44
- accordionItem.style.setProperty('--_panel-h', `${content.offsetHeight}px`);
43
+ // 次フレームで高さセット( 目標の高さ = content の高さ )
44
+ accordionItem.style.setProperty('--_panel-h', `${content.offsetHeight}px`);
45
45
 
46
- // さらに1フレーム待機
47
- await waitFrame();
46
+ // さらに1フレーム待機
47
+ await waitFrame();
48
48
 
49
- // アニメーション開始
50
- accordionItem.setAttribute('data-opened', '');
51
- button.setAttribute('aria-expanded', 'true');
49
+ // アニメーション開始
50
+ accordionItem.setAttribute('data-opened', '');
51
+ button.setAttribute('aria-expanded', 'true');
52
52
 
53
- // アニメーションを待つ
54
- const status = await waitAnimation(panel);
53
+ // アニメーションを待つ
54
+ const status = await waitAnimation(panel);
55
55
 
56
- // アニメーションが最後まで完了した時、--_panel-h削除(高さセットしたままだとリサイズできない)
57
- if ('canceled' !== status) {
58
- accordionItem.style.removeProperty('--_panel-h');
59
- }
56
+ // アニメーションが最後まで完了した時、--_panel-h削除(高さセットしたままだとリサイズできない)
57
+ if ('canceled' !== status) {
58
+ accordionItem.style.removeProperty('--_panel-h');
59
+ }
60
60
  }
61
61
 
62
62
  async function closeAccordion(accordionItem) {
63
- const { panel, button } = getAccordionElements(accordionItem);
63
+ const { panel, button } = getAccordionElements(accordionItem);
64
64
 
65
- // アニメーションがあれば一時停止
66
- maybePauseAnimation(panel);
65
+ // アニメーションがあれば一時停止
66
+ maybePauseAnimation(panel);
67
67
 
68
- // 現在の高さを一旦セットする
69
- accordionItem.style.setProperty('--_panel-h', `${panel.offsetHeight}px`);
68
+ // 現在の高さを一旦セットする
69
+ accordionItem.style.setProperty('--_panel-h', `${panel.offsetHeight}px`);
70
70
 
71
- // 1フレーム待機
72
- await waitFrame();
71
+ // 1フレーム待機
72
+ await waitFrame();
73
73
 
74
- // 次フレームで属性を削除
75
- accordionItem.removeAttribute('data-opened');
76
- button.setAttribute('aria-expanded', 'false');
74
+ // 次フレームで属性を削除
75
+ accordionItem.removeAttribute('data-opened');
76
+ button.setAttribute('aria-expanded', 'false');
77
77
 
78
- // 変数削除して 0px へ向けてアニメーション開始
79
- accordionItem.style.removeProperty('--_panel-h');
78
+ // 変数削除して 0px へ向けてアニメーション開始
79
+ accordionItem.style.removeProperty('--_panel-h');
80
80
 
81
- // アニメーションを待つ
82
- const status = await waitAnimation(panel);
81
+ // アニメーションを待つ
82
+ const status = await waitAnimation(panel);
83
83
 
84
- // アニメーションが最後まで完了したら、hidden付与
85
- if ('canceled' !== status) {
86
- panel.setAttribute('hidden', ACCORDION_HIDDEN_VALUE);
87
- }
84
+ // アニメーションが最後まで完了したら、hidden付与
85
+ if ('canceled' !== status) {
86
+ panel.setAttribute('hidden', ACCORDION_HIDDEN_VALUE);
87
+ }
88
88
  }
89
89
 
90
90
  // アコーディオンのトグル処理
91
91
  function toggleAccordion(accordionItem) {
92
- if (accordionItem.hasAttribute('data-opened')) {
93
- // 自身を閉じる
94
- closeAccordion(accordionItem);
95
- } else {
96
- // 親に data-allow-multiple がついていなければ、他のアコーディオンを閉じる
97
- maybeCloseOpenedItems(accordionItem);
98
-
99
- // 自身を開く
100
- openAccordion(accordionItem);
101
- }
92
+ if (accordionItem.hasAttribute('data-opened')) {
93
+ // 自身を閉じる
94
+ closeAccordion(accordionItem);
95
+ } else {
96
+ // 親に data-allow-multiple がついていなければ、他のアコーディオンを閉じる
97
+ maybeCloseOpenedItems(accordionItem);
98
+
99
+ // 自身を開く
100
+ openAccordion(accordionItem);
101
+ }
102
102
  }
103
103
 
104
104
  /**
105
105
  * 個別のアコーディオンにイベントをセット(React用にクリーンアップ関数を返す)
106
106
  */
107
107
  export const setEvent = (accordionItem) => {
108
- const { button, panel } = getAccordionElements(accordionItem);
109
-
110
- // until-found のオン・オフが使い分けれるように、最初に初期値を取得
111
- if (panel.hasAttribute('hidden')) {
112
- ACCORDION_HIDDEN_VALUE = panel.getAttribute('hidden');
113
- }
114
-
115
- // clickイベント登録
116
- const _clickEvent = (e) => {
117
- e.preventDefault(); // hidden="until-found" の自動付け外しを無効化
118
- toggleAccordion(accordionItem);
119
- };
120
-
121
- // beforematchイベント登録 (ページ検索時などはこっちが発火する)
122
- const _beforematchEvent = (e) => {
123
- e.preventDefault(); // hidden="until-found" の自動付け外しを無効化
124
- toggleAccordion(accordionItem);
125
- };
126
-
127
- button.addEventListener('click', _clickEvent);
128
- panel.addEventListener('beforematch', _beforematchEvent);
129
-
130
- // react用: useEffect でアンマウントされた時にremoveEventListenerしないと2重でイベントが登録してしまう
131
- return () => {
132
- button.removeEventListener('click', _clickEvent);
133
- panel.removeEventListener('beforematch', _beforematchEvent);
134
- };
108
+ const { button, panel } = getAccordionElements(accordionItem);
109
+
110
+ // until-found のオン・オフが使い分けれるように、最初に初期値を取得
111
+ if (panel.hasAttribute('hidden')) {
112
+ ACCORDION_HIDDEN_VALUE = panel.getAttribute('hidden');
113
+ }
114
+
115
+ // clickイベント登録
116
+ const _clickEvent = (e) => {
117
+ e.preventDefault(); // hidden="until-found" の自動付け外しを無効化
118
+ toggleAccordion(accordionItem);
119
+ };
120
+
121
+ // beforematchイベント登録 (ページ検索時などはこっちが発火する)
122
+ const _beforematchEvent = (e) => {
123
+ e.preventDefault(); // hidden="until-found" の自動付け外しを無効化
124
+ toggleAccordion(accordionItem);
125
+ };
126
+
127
+ button.addEventListener('click', _clickEvent);
128
+ panel.addEventListener('beforematch', _beforematchEvent);
129
+
130
+ // react用: useEffect でアンマウントされた時にremoveEventListenerしないと2重でイベントが登録してしまう
131
+ return () => {
132
+ button.removeEventListener('click', _clickEvent);
133
+ panel.removeEventListener('beforematch', _beforematchEvent);
134
+ };
135
135
  };
136
136
 
137
137
  /**
138
138
  * ページ内の全アコーディオンにイベントをセット(Astro用)
139
139
  */
140
140
  const setAccordion = () => {
141
- const accordionAll = document.querySelectorAll('.c--accordion_item');
142
- accordionAll.forEach((accordionItem) => {
143
- setEvent(accordionItem);
144
- });
141
+ const accordionAll = document.querySelectorAll('.c--accordion_item');
142
+ accordionAll.forEach((accordionItem) => {
143
+ setEvent(accordionItem);
144
+ });
145
145
  };
146
146
  export default setAccordion;
@@ -8,10 +8,10 @@ const { icon, layout, flow, ...alertProps } = getAlertProps(Astro.props);
8
8
  ---
9
9
 
10
10
  <Lism layout={layout} {...alertProps}>
11
- <Center isSide={layout === 'sideMain'} c='keycolor' fz='xl' fxsh='0'>
12
- <Icon icon={icon} />
13
- </Center>
14
- <Flow flow={flow}>
15
- <slot />
16
- </Flow>
11
+ <Center isSide={layout === 'sideMain'} c="keycolor" fz="xl" fxsh="0">
12
+ <Icon icon={icon} />
13
+ </Center>
14
+ <Flow flow={flow}>
15
+ <slot />
16
+ </Flow>
17
17
  </Lism>
@@ -1,30 +1,30 @@
1
1
  import PRESETS from './presets';
2
2
 
3
3
  export type AlertProps = {
4
- type?: string;
5
- keycolor?: string;
6
- layout?: string;
7
- icon?: string;
8
- flow?: string;
9
- [key: string]: unknown;
4
+ type?: string;
5
+ keycolor?: string;
6
+ layout?: string;
7
+ icon?: string;
8
+ flow?: string;
9
+ [key: string]: unknown;
10
10
  };
11
11
 
12
12
  export default function getAlertProps({ type = 'alert', keycolor, layout = 'flex', icon, flow = 's', ...props }: AlertProps) {
13
- const presetData = type ? PRESETS[type] : null;
14
- const _icon = icon || presetData?.icon || 'info';
15
- const _color = keycolor || presetData?.color || 'currentColor';
13
+ const presetData = type ? PRESETS[type] : null;
14
+ const _icon = icon || presetData?.icon || 'info';
15
+ const _color = keycolor || presetData?.color || 'currentColor';
16
16
 
17
- return {
18
- icon: _icon,
19
- layout,
20
- flow,
21
- lismClass: 'c--alert u--cbox',
22
- keycolor: _color,
23
- ai: 'center',
24
- p: '15',
25
- g: '15',
26
- bd: true,
27
- bdrs: '10',
28
- ...props,
29
- };
17
+ return {
18
+ icon: _icon,
19
+ layout,
20
+ flow,
21
+ lismClass: 'c--alert u--cbox',
22
+ keycolor: _color,
23
+ ai: 'center',
24
+ p: '15',
25
+ g: '15',
26
+ bd: true,
27
+ bdrs: '10',
28
+ ...props,
29
+ };
30
30
  }
@@ -1,33 +1,33 @@
1
1
  type PresetData = {
2
- icon: string;
3
- color: string;
2
+ icon: string;
3
+ color: string;
4
4
  };
5
5
 
6
6
  const PRESETS: Record<string, PresetData> = {
7
- alert: {
8
- icon: 'alert',
9
- color: 'red',
10
- },
11
- point: {
12
- icon: 'lightbulb',
13
- color: 'orange',
14
- },
15
- warning: {
16
- icon: 'warning',
17
- color: 'yellow',
18
- },
19
- check: {
20
- icon: 'check-circle',
21
- color: 'green',
22
- },
23
- help: {
24
- icon: 'question',
25
- color: 'purple',
26
- },
27
- info: {
28
- icon: 'info',
29
- color: 'blue',
30
- },
7
+ alert: {
8
+ icon: 'alert',
9
+ color: 'red',
10
+ },
11
+ point: {
12
+ icon: 'lightbulb',
13
+ color: 'orange',
14
+ },
15
+ warning: {
16
+ icon: 'warning',
17
+ color: 'yellow',
18
+ },
19
+ check: {
20
+ icon: 'check-circle',
21
+ color: 'green',
22
+ },
23
+ help: {
24
+ icon: 'question',
25
+ color: 'purple',
26
+ },
27
+ info: {
28
+ icon: 'info',
29
+ color: 'blue',
30
+ },
31
31
  };
32
32
 
33
33
  export default PRESETS;