@db-ux/react-core-components 4.9.1 → 4.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 (131) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/README.md +97 -35
  3. package/dist/components/accordion/accordion.js +102 -86
  4. package/dist/components/accordion/model.js +4 -2
  5. package/dist/components/accordion-item/accordion-item.d.ts +2 -1
  6. package/dist/components/accordion-item/accordion-item.js +89 -56
  7. package/dist/components/accordion-item/model.d.ts +4 -0
  8. package/dist/components/badge/badge.js +72 -32
  9. package/dist/components/badge/model.js +12 -1
  10. package/dist/components/brand/brand.js +60 -13
  11. package/dist/components/button/button.js +75 -21
  12. package/dist/components/button/model.js +13 -2
  13. package/dist/components/card/card.js +65 -15
  14. package/dist/components/card/model.js +8 -2
  15. package/dist/components/checkbox/checkbox.js +163 -157
  16. package/dist/components/custom-button/custom-button.js +65 -10
  17. package/dist/components/custom-select/custom-select.js +509 -727
  18. package/dist/components/custom-select/model.js +8 -1
  19. package/dist/components/custom-select-dropdown/custom-select-dropdown.js +62 -11
  20. package/dist/components/custom-select-dropdown/model.js +8 -1
  21. package/dist/components/custom-select-form-field/custom-select-form-field.js +57 -10
  22. package/dist/components/custom-select-list/custom-select-list.js +60 -11
  23. package/dist/components/custom-select-list-item/custom-select-list-item.js +89 -32
  24. package/dist/components/custom-select-list-item/model.js +4 -1
  25. package/dist/components/divider/divider.js +60 -10
  26. package/dist/components/divider/model.js +4 -2
  27. package/dist/components/drawer/drawer.js +118 -97
  28. package/dist/components/drawer/model.js +14 -4
  29. package/dist/components/header/header.js +143 -65
  30. package/dist/components/icon/icon.js +61 -12
  31. package/dist/components/icon/model.js +11 -1
  32. package/dist/components/infotext/infotext.js +62 -12
  33. package/dist/components/input/input.js +198 -167
  34. package/dist/components/input/model.js +21 -5
  35. package/dist/components/link/link.js +70 -12
  36. package/dist/components/link/model.js +8 -3
  37. package/dist/components/navigation/navigation.js +57 -11
  38. package/dist/components/navigation-item/model.d.ts +4 -0
  39. package/dist/components/navigation-item/navigation-item.js +117 -81
  40. package/dist/components/notification/model.js +12 -3
  41. package/dist/components/notification/notification.js +100 -32
  42. package/dist/components/page/model.js +4 -2
  43. package/dist/components/page/page.js +74 -46
  44. package/dist/components/popover/popover.js +126 -125
  45. package/dist/components/radio/radio.js +124 -85
  46. package/dist/components/section/section.js +59 -10
  47. package/dist/components/select/select.js +188 -191
  48. package/dist/components/stack/model.js +14 -4
  49. package/dist/components/stack/stack.js +63 -10
  50. package/dist/components/switch/switch.js +182 -150
  51. package/dist/components/tab-item/tab-item.js +105 -76
  52. package/dist/components/tab-list/tab-list.js +60 -11
  53. package/dist/components/tab-panel/tab-panel.js +59 -13
  54. package/dist/components/tabs/model.js +4 -2
  55. package/dist/components/tabs/tabs.js +191 -178
  56. package/dist/components/tag/model.js +4 -1
  57. package/dist/components/tag/tag.js +91 -32
  58. package/dist/components/textarea/model.js +13 -2
  59. package/dist/components/textarea/textarea.js +165 -150
  60. package/dist/components/tooltip/model.js +4 -1
  61. package/dist/components/tooltip/tooltip.js +119 -115
  62. package/dist/index.js +64 -81
  63. package/dist/shared/constants.js +32 -94
  64. package/dist/shared/figma.d.ts +12 -6
  65. package/dist/shared/model.js +73 -22
  66. package/dist/utils/document-click-listener.js +26 -29
  67. package/dist/utils/document-scroll-listener.js +30 -38
  68. package/dist/utils/floating-components.js +107 -358
  69. package/dist/utils/form-components.js +34 -60
  70. package/dist/utils/index.js +49 -167
  71. package/dist/utils/navigation.js +68 -135
  72. package/dist/utils/react.js +10 -15
  73. package/package.json +11 -8
  74. package/dist/components/accordion/index.js +0 -1
  75. package/dist/components/accordion-item/index.js +0 -1
  76. package/dist/components/accordion-item/model.js +0 -1
  77. package/dist/components/badge/index.js +0 -1
  78. package/dist/components/brand/index.js +0 -1
  79. package/dist/components/brand/model.js +0 -1
  80. package/dist/components/button/index.js +0 -1
  81. package/dist/components/card/index.js +0 -1
  82. package/dist/components/checkbox/index.js +0 -1
  83. package/dist/components/checkbox/model.js +0 -1
  84. package/dist/components/custom-button/index.js +0 -1
  85. package/dist/components/custom-button/model.js +0 -1
  86. package/dist/components/custom-select/index.js +0 -1
  87. package/dist/components/custom-select-dropdown/index.js +0 -1
  88. package/dist/components/custom-select-form-field/index.js +0 -1
  89. package/dist/components/custom-select-form-field/model.js +0 -1
  90. package/dist/components/custom-select-list/index.js +0 -1
  91. package/dist/components/custom-select-list/model.js +0 -1
  92. package/dist/components/custom-select-list-item/index.js +0 -1
  93. package/dist/components/divider/index.js +0 -1
  94. package/dist/components/drawer/index.js +0 -1
  95. package/dist/components/header/index.js +0 -1
  96. package/dist/components/header/model.js +0 -1
  97. package/dist/components/icon/index.js +0 -1
  98. package/dist/components/infotext/index.js +0 -1
  99. package/dist/components/infotext/model.js +0 -1
  100. package/dist/components/input/index.js +0 -1
  101. package/dist/components/link/index.js +0 -1
  102. package/dist/components/navigation/index.js +0 -1
  103. package/dist/components/navigation/model.js +0 -1
  104. package/dist/components/navigation-item/index.js +0 -1
  105. package/dist/components/navigation-item/model.js +0 -1
  106. package/dist/components/notification/index.js +0 -1
  107. package/dist/components/page/index.js +0 -1
  108. package/dist/components/popover/index.js +0 -1
  109. package/dist/components/popover/model.js +0 -1
  110. package/dist/components/radio/index.js +0 -1
  111. package/dist/components/radio/model.js +0 -1
  112. package/dist/components/section/index.js +0 -1
  113. package/dist/components/section/model.js +0 -1
  114. package/dist/components/select/index.js +0 -1
  115. package/dist/components/select/model.js +0 -1
  116. package/dist/components/stack/index.js +0 -1
  117. package/dist/components/switch/index.js +0 -1
  118. package/dist/components/switch/model.js +0 -1
  119. package/dist/components/tab-item/index.js +0 -1
  120. package/dist/components/tab-item/model.js +0 -1
  121. package/dist/components/tab-list/index.js +0 -1
  122. package/dist/components/tab-list/model.js +0 -1
  123. package/dist/components/tab-panel/index.js +0 -1
  124. package/dist/components/tab-panel/model.js +0 -1
  125. package/dist/components/tabs/index.js +0 -1
  126. package/dist/components/tag/index.js +0 -1
  127. package/dist/components/textarea/index.js +0 -1
  128. package/dist/components/tooltip/index.js +0 -1
  129. package/dist/shared/examples/index.js +0 -4
  130. package/dist/shared/figma.js +0 -1
  131. package/dist/shared/showcase/show-code-link.js +0 -51
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @db-ux/react-core-components
2
2
 
3
+ ## 4.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - feat(`DBAccordionItem`): add `open` prop to control the expanded state of an accordion item programmatically. - [see commit 8e7c85d](https://github.com/db-ux-design-system/core-web/commit/8e7c85dfba9e0b013fce9db2151545b8f336a29a)
8
+
9
+ - refactor(form components): replace hard 25ch label width limit with customizable CSS variable `--db-label-max-size` (defaults to `100%`). To restore the previous behavior, set `--db-label-max-size: 25ch;` in your project styles. - [see commit 08b1234](https://github.com/db-ux-design-system/core-web/commit/08b1234342e3c0d622116d528a979ff53d7e2356)
10
+
3
11
  ## 4.9.1
4
12
 
5
13
  ### Patch Changes
@@ -207,7 +215,7 @@ _version bump_
207
215
 
208
216
  - fix: set DBTabItem internal state `_selected` correctly - [see commit f7625cb](https://github.com/db-ux-design-system/core-web/commit/f7625cbd9d64513527e826c9d2c1ef42b2734a4b):
209
217
 
210
- - Now also sets aria-selected=true|false correctly which improves screen reader behaviour
218
+ - Now also sets aria-selected=true|false correctly which improves screen reader behaviour
211
219
 
212
220
  ## 4.2.1
213
221
 
package/README.md CHANGED
@@ -6,49 +6,83 @@
6
6
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
7
7
 
8
8
  A React library containing all styles & components of [DB UX Design System (technical components)](https://github.com/db-ux-design-system/core-web).
9
-
10
- > **Note:** Find more information about specific components [here](https://design-system.deutschebahn.com/core-web/review/main)
9
+ We also provide more information about specific components. This information is in our [Design System documentation](https://design-system.deutschebahn.com/documentation/get-started/).
11
10
 
12
11
  ## Install
13
12
 
14
13
  ```shell
15
- npm i @db-ux/react-core-components
14
+ pnpm add @db-ux/react-core-components @db-ux/core-components @db-ux/core-foundations --save-dev
16
15
  ```
17
16
 
18
- > **Note:** This will install [`@db-ux/core-foundations`](https://www.npmjs.com/package/@db-ux/core-foundations) and [`@db-ux/core-components`](https://www.npmjs.com/package/@db-ux/core-components) as well which contains the `css`/`scss` files
19
-
20
17
  ## Styling Dependencies
21
18
 
22
- Import the styles in scss or css. Based on your technology the file names could be different.
19
+ ### Vite Plugin
20
+
21
+ If you're using Vite, you can use the [`@db-ux/core-vite-plugin`](https://www.npmjs.com/package/@db-ux/core-vite-plugin) which simplifies the CSS setup to a single import.
22
+
23
+ ```shell
24
+ pnpm add @db-ux/core-vite-plugin --save-dev
25
+ ```
23
26
 
24
- - Default (relative): points to `../assets`
25
- - Rollup (rollup): points to `@db-ux/core-foundations/assets`
26
- - Webpack (webpack): points to `~@db-ux/core-foundations/assets`
27
+ Add the plugin to your `vite.config.ts`:
27
28
 
28
- <details>
29
- <summary><strong>SCSS</strong></summary>
29
+ ```ts
30
+ import { defineConfig } from "vite";
31
+ import dbUxPlugin from "@db-ux/core-vite-plugin";
30
32
 
31
- ```scss
32
- // index.scss
33
- @forward "@db-ux/core-foundations/build/styles/theme/rollup"; // Palette tokens
34
- @forward "@db-ux/core-foundations/build/styles/bundle"; // Semantic tokens
35
- @forward "@db-ux/core-foundations/build/styles/icons/rollup"; // Icon fonts
36
- @forward "@db-ux/core-components/build/styles/rollup"; // Component styling
33
+ export default defineConfig({
34
+ plugins: [dbUxPlugin()]
35
+ });
37
36
  ```
38
37
 
39
- </details>
40
- <details>
41
- <summary><strong>CSS</strong></summary>
38
+ Then import the plugin in your CSS file:
42
39
 
43
- ```tsx
44
- // main.tsx — order matters!
45
- import "@db-ux/core-foundations/build/styles/theme/rollup.css"; // Palette tokens
46
- import "@db-ux/core-foundations/build/styles/bundle.css"; // Semantic tokens
47
- import "@db-ux/core-foundations/build/styles/icons/rollup.css"; // Icon fonts
48
- import "@db-ux/core-components/build/styles/rollup.css"; // Component styling
40
+ ```css
41
+ /* index.css */
42
+ @import "@db-ux/core-vite-plugin/index.css";
43
+ ```
44
+
45
+ 📖 **[Learn more about `@db-ux/core-vite-plugin` node package](https://www.npmjs.com/package/@db-ux/core-vite-plugin)**
46
+
47
+ ### PostCSS Plugin (recommended)
48
+
49
+ We recommend using the [`@db-ux/core-postcss-plugin`](https://www.npmjs.com/package/@db-ux/core-postcss-plugin) to reduce your bundle size. It flattens CSS custom properties by resolving `var()`, `calc()`, `color-mix()`, and `light-dark()` at build time, removing unused declarations.
50
+
51
+ ```shell
52
+ pnpm add @db-ux/core-postcss-plugin --save-dev
53
+ ```
54
+
55
+ Configure it in `vite.config.ts`:
56
+
57
+ ```ts
58
+ import { defineConfig } from "vite";
59
+ import { dbUxFlatten } from "@db-ux/core-postcss-plugin";
60
+
61
+ export default defineConfig({
62
+ css: {
63
+ transformer: "postcss", // required for Vite 8+ (default: 'lightningcss')
64
+ postcss: {
65
+ plugins: [dbUxFlatten()]
66
+ }
67
+ }
68
+ });
49
69
  ```
50
70
 
51
- </details>
71
+ 📖 **[Learn more about `@db-ux/core-postcss-plugin` node package](https://www.npmjs.com/package/@db-ux/core-postcss-plugin)**
72
+
73
+ ### Manual CSS Setup
74
+
75
+ If you're not using Vite or prefer manual setup, import the styles in your main CSS file:
76
+
77
+ ```css
78
+ /* index.css */
79
+ @layer whitelabel-theme, db-ux;
80
+ /* You may want to include another theme here, this is a whitelabel theme! So instead of including the following line of code, please have a look at the DB Theme section */
81
+ @import "@db-ux/core-foundations/build/styles/theme/rollup.css"
82
+ layer(whitelabel-theme);
83
+
84
+ @import "@db-ux/core-components/build/styles/bundle.css" layer(db-ux);
85
+ ```
52
86
 
53
87
  ### Vite 8
54
88
 
@@ -86,8 +120,6 @@ export default defineConfig({
86
120
  });
87
121
  ```
88
122
 
89
- > **Note:** The `@db-ux/core-components/build/styles/relative` file contains optional and all components styles. If you consider performance issues see [@db-ux/core-components](https://www.npmjs.com/package/@db-ux/core-components) for more information.
90
-
91
123
  ### Next 16
92
124
 
93
125
  Starting with Next 16, the default CSS minifier was changed to [LightningCSS](https://lightningcss.dev/), which provides buggy transformations for modern CSS features used by the DB UX Design System (e.g. `light-dark()` CSS function). We might provide a specific configuration necessary to mitigate those problems in the near future. To keep CSS output stable in the meantime, configure `next.config.ts` like this:
@@ -116,10 +148,11 @@ In case that you're building a website or application for Deutsche Bahn, you'll
116
148
  ## Usage
117
149
 
118
150
  ```tsx
119
- import { DBButton } from '@db-ux/react-core-components';
120
- ...
121
- <DBButton icon="x_placeholder" onClick={()=>{console.log("Test")}}>Test</DBButton>
122
- ...
151
+ import { DBButton } from "@db-ux/react-core-components";
152
+
153
+ <DBButton variant="brand" onClick={() => console.log("clicked")}>
154
+ Add item to cart
155
+ </DBButton>;
123
156
  ```
124
157
 
125
158
  ## AI Agent Support
@@ -136,7 +169,7 @@ npx @db-ux/agent-cli
136
169
 
137
170
  This will create or update `.github/copilot-instructions.md` with component documentation based on your installed `@db-ux` packages, helping AI agents provide better suggestions.
138
171
 
139
- 📖 **[Learn more about `@db-ux/agent-cli` node package](packages/agent-cli/README.md)**
172
+ 📖 **[Learn more about `@db-ux/agent-cli` node package](https://www.npmjs.com/package/@db-ux/agent-cli)**
140
173
 
141
174
  ## Code Quality
142
175
 
@@ -145,7 +178,7 @@ To enforce correct usage of DB UX Design System components in your React project
145
178
  ### Installation
146
179
 
147
180
  ```shell
148
- npm install eslint @db-ux/core-eslint-plugin @typescript-eslint/parser --save-dev
181
+ pnpm add eslint @db-ux/core-eslint-plugin @typescript-eslint/parser --save-dev
149
182
  ```
150
183
 
151
184
  ### Setup
@@ -176,6 +209,35 @@ export default [
176
209
 
177
210
  📖 **[Learn more about `@db-ux/core-eslint-plugin` node package](https://www.npmjs.com/package/@db-ux/core-eslint-plugin)**
178
211
 
212
+ ## Stylelint
213
+
214
+ To validate correct usage of DB UX Design System tokens in your CSS/SCSS, use the [`@db-ux/core-stylelint`](https://www.npmjs.com/package/@db-ux/core-stylelint) plugin.
215
+
216
+ ### Installation
217
+
218
+ ```shell
219
+ pnpm add stylelint @db-ux/core-stylelint --save-dev
220
+ ```
221
+
222
+ ### Setup
223
+
224
+ Add to your `.stylelintrc.json`:
225
+
226
+ ```json
227
+ {
228
+ "plugins": ["@db-ux/core-stylelint"],
229
+ "rules": {
230
+ "db-ux/use-spacings": [true],
231
+ "db-ux/use-sizing": [true],
232
+ "db-ux/use-border-width": [true],
233
+ "db-ux/use-border-radius": [true],
234
+ "db-ux/use-border-color": [true]
235
+ }
236
+ }
237
+ ```
238
+
239
+ 📖 **[Learn more about `@db-ux/core-stylelint` node package](https://www.npmjs.com/package/@db-ux/core-stylelint)**
240
+
179
241
  ## Deutsche Bahn brand
180
242
 
181
243
  As we'd like to perfectly support our users and customers on their digital journey, the usage of Deutsche Bahn brand and trademarks are bound of clear guidelines and restrictions even if being used with the code that we're providing with this product; Deutsche Bahn fully reserves all rights regarding the Deutsche Bahn brand, even though that we're providing the code of DB UX Design System products free to use and release it under the Apache 2.0 license.
@@ -1,88 +1,104 @@
1
1
  "use client";
2
- import * as React from "react";
3
- import { filterPassingProps, getRootProps } from "../../utils/react";
4
- import { useState, useRef, useEffect, forwardRef } from "react";
5
- import { cls } from "../../utils";
6
- import DBAccordionItem from "../accordion-item/accordion-item";
7
- import { useId } from "react";
8
- function DBAccordionFn(props, component) {
9
- var _a, _b, _c;
10
- const uuid = useId();
11
- const _ref = component || useRef(component);
12
- const [_name, set_name] = useState(() => "");
13
- const [initialized, setInitialized] = useState(() => false);
14
- const [_initOpenIndexDone, set_initOpenIndexDone] = useState(() => false);
15
- function convertItems() {
16
- try {
17
- if (typeof props.items === "string") {
18
- return JSON.parse(props.items);
19
- }
20
- return props.items;
21
- }
22
- catch (error) {
23
- console.error(error);
24
- }
25
- return [];
26
- }
27
- useEffect(() => {
28
- setInitialized(true);
29
- set_initOpenIndexDone(true);
30
- }, []);
31
- useEffect(() => {
32
- // If we have a single behavior we first check for
33
- // props.name otherwise for state_id
34
- if (initialized) {
35
- if (props.behavior === "single") {
36
- if (props.name) {
37
- if (_name !== props.name) {
38
- set_name(props.name);
39
- }
40
- }
41
- else {
42
- set_name(`accordion-${uuid}`);
43
- }
44
- }
45
- else {
46
- set_name("");
47
- }
48
- }
49
- }, [initialized, props.name, props.behavior]);
50
- useEffect(() => {
51
- if (_ref.current) {
52
- const childDetails = _ref.current.getElementsByTagName("details");
53
- if (childDetails) {
54
- for (const details of Array.from(childDetails)) {
55
- if (_name === "") {
56
- details.removeAttribute("name");
57
- }
58
- else {
59
- details.name = _name !== null && _name !== void 0 ? _name : "";
60
- }
61
- }
62
- }
63
- }
64
- }, [_ref.current, _name]);
65
- useEffect(() => {
66
- if (_ref.current && _initOpenIndexDone) {
67
- if ((props === null || props === void 0 ? void 0 : props.initOpenIndex) && props.initOpenIndex.length > 0) {
68
- const childDetails = _ref.current.getElementsByTagName("details");
69
- if (childDetails) {
70
- const initOpenIndex = props.behavior === "single" && props.initOpenIndex.length > 1
71
- ? [props.initOpenIndex[0]] // use only one index for behavior=single
72
- : props.initOpenIndex;
73
- Array.from(childDetails).forEach((details, index) => {
74
- if (initOpenIndex === null || initOpenIndex === void 0 ? void 0 : initOpenIndex.includes(index)) {
75
- details.open = true;
76
- }
77
- });
78
- }
79
- }
80
- set_initOpenIndexDone(false);
81
- }
82
- }, [_ref.current, _initOpenIndexDone, props.initOpenIndex]);
83
- return (React.createElement("ul", Object.assign({ ref: _ref }, filterPassingProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font", "data-density"]), { id: (_a = props.id) !== null && _a !== void 0 ? _a : (_b = props.propOverrides) === null || _b === void 0 ? void 0 : _b.id }, getRootProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font", "data-density"]), { className: cls("db-accordion", props.className), "data-variant": props.variant }),
84
- !props.items ? React.createElement(React.Fragment, null, props.children) : null,
85
- props.items ? (React.createElement(React.Fragment, null, (_c = convertItems()) === null || _c === void 0 ? void 0 : _c.map((item, index) => (React.createElement(DBAccordionItem, { key: `accordion-item-${index}`, headlinePlain: item.headlinePlain, disabled: item.disabled, text: item.text }))))) : null));
2
+ import { filterPassingProps as e, getRootProps as t } from "../../utils/react.js";
3
+ import { cls as n } from "../../utils/index.js";
4
+ import r from "../accordion-item/accordion-item.js";
5
+ import { forwardRef as i, useEffect as a, useId as o, useRef as s, useState as c } from "react";
6
+ import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
7
+ //#region src/components/accordion/accordion.tsx
8
+ function f(i, f) {
9
+ let p = o(), m = f || s(f), [h, g] = c(() => ""), [_, v] = c(() => !1), [y, b] = c(() => !1);
10
+ function x() {
11
+ try {
12
+ return typeof i.items == "string" ? JSON.parse(i.items) : i.items;
13
+ } catch (e) {
14
+ console.error(e);
15
+ }
16
+ return [];
17
+ }
18
+ return a(() => {
19
+ v(!0), b(!0);
20
+ }, []), a(() => {
21
+ _ && m.current && (i.behavior === "single" ? i.name ? h !== i.name && g(i.name) : g(`accordion-${p}`) : g(""));
22
+ }, [
23
+ _,
24
+ i.name,
25
+ i.behavior
26
+ ]), a(() => {
27
+ if (m.current) {
28
+ let e = m.current.getElementsByTagName("details");
29
+ if (e) for (let t of Array.from(e)) h === "" ? t.removeAttribute("name") : t.name = h ?? "";
30
+ }
31
+ }, [m.current, h]), a(() => {
32
+ if (m.current && y) {
33
+ if (i?.initOpenIndex && i.initOpenIndex.length > 0) {
34
+ let e = m.current.getElementsByTagName("details");
35
+ if (e) {
36
+ let t = i.behavior === "single" && i.initOpenIndex.length > 1 ? [i.initOpenIndex[0]] : i.initOpenIndex;
37
+ Array.from(e).forEach((e, n) => {
38
+ t?.includes(n) && (e.open = !0);
39
+ });
40
+ }
41
+ }
42
+ b(!1);
43
+ }
44
+ }, [
45
+ m.current,
46
+ y,
47
+ i.initOpenIndex
48
+ ]), /* @__PURE__ */ d("ul", {
49
+ ref: m,
50
+ ...e(i, [
51
+ "data-icon-variant",
52
+ "data-icon-variant-before",
53
+ "data-icon-variant-after",
54
+ "data-icon-weight",
55
+ "data-icon-weight-before",
56
+ "data-icon-weight-after",
57
+ "data-interactive",
58
+ "data-force-mobile",
59
+ "data-color",
60
+ "data-container-color",
61
+ "data-bg-color",
62
+ "data-on-bg-color",
63
+ "data-color-scheme",
64
+ "data-font-size",
65
+ "data-headline-size",
66
+ "data-divider",
67
+ "data-focus",
68
+ "data-font",
69
+ "data-density"
70
+ ]),
71
+ id: i.id ?? i.propOverrides?.id,
72
+ ...t(i, [
73
+ "data-icon-variant",
74
+ "data-icon-variant-before",
75
+ "data-icon-variant-after",
76
+ "data-icon-weight",
77
+ "data-icon-weight-before",
78
+ "data-icon-weight-after",
79
+ "data-interactive",
80
+ "data-force-mobile",
81
+ "data-color",
82
+ "data-container-color",
83
+ "data-bg-color",
84
+ "data-on-bg-color",
85
+ "data-color-scheme",
86
+ "data-font-size",
87
+ "data-headline-size",
88
+ "data-divider",
89
+ "data-focus",
90
+ "data-font",
91
+ "data-density"
92
+ ]),
93
+ className: n("db-accordion", i.className),
94
+ "data-variant": i.variant,
95
+ children: [i.items ? null : /* @__PURE__ */ u(l, { children: i.children }), i.items ? /* @__PURE__ */ u(l, { children: x()?.map((e, t) => /* @__PURE__ */ u(r, {
96
+ headlinePlain: e.headlinePlain,
97
+ disabled: e.disabled,
98
+ text: e.text
99
+ }, `accordion-item-${t}`)) }) : null]
100
+ });
86
101
  }
87
- const DBAccordion = forwardRef(DBAccordionFn);
88
- export default DBAccordion;
102
+ var p = i(f);
103
+ //#endregion
104
+ export { p as default };
@@ -1,2 +1,4 @@
1
- export const AccordionVariantList = ['divider', 'card'];
2
- export const AccordionBehaviorList = ['multiple', 'single'];
1
+ //#region src/components/accordion/model.ts
2
+ var e = ["divider", "card"], t = ["multiple", "single"];
3
+ //#endregion
4
+ export { t as AccordionBehaviorList, e as AccordionVariantList };
@@ -1,6 +1,7 @@
1
1
  import * as React from "react";
2
- declare const DBAccordionItem: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<any>, keyof import("../../shared/model").GlobalProps | "name" | "text" | "defaultOpen" | "disabled" | "headline" | "headlinePlain" | keyof import("../../shared/model").ToggleEventProps> & {
2
+ declare const DBAccordionItem: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<any>, keyof import("../../shared/model").GlobalProps | "name" | "text" | "defaultOpen" | "open" | "disabled" | "headline" | "headlinePlain" | keyof import("../../shared/model").ToggleEventProps> & {
3
3
  defaultOpen?: boolean;
4
+ open?: boolean | string;
4
5
  disabled?: boolean | string;
5
6
  headline?: any;
6
7
  headlinePlain?: string;
@@ -1,58 +1,91 @@
1
1
  "use client";
2
- import * as React from "react";
3
- import { filterPassingProps, getRootProps } from "../../utils/react";
4
- import { useState, useRef, useEffect, forwardRef } from "react";
5
- import { cls, getBooleanAsString } from "../../utils";
6
- function DBAccordionItemFn(props, component) {
7
- var _a, _b;
8
- const _ref = component || useRef(component);
9
- const [_open, set_open] = useState(() => false);
10
- const [_name, set_name] = useState(() => undefined);
11
- const [initialized, setInitialized] = useState(() => false);
12
- function handleNameAttribute() {
13
- if (_ref.current) {
14
- const setAttribute = _ref.current.setAttribute;
15
- _ref.current.setAttribute = (attribute, value) => {
16
- setAttribute.call(_ref.current, attribute, value);
17
- if (attribute === "name") {
18
- set_name(value);
19
- }
20
- };
21
- }
22
- }
23
- function handleToggle(event) {
24
- // We need this for react https://github.com/facebook/react/issues/15486#issuecomment-488028431
25
- event === null || event === void 0 ? void 0 : event.preventDefault();
26
- const newStateOpen = !_open;
27
- if (props.onToggle) {
28
- props.onToggle(newStateOpen);
29
- }
30
- set_open(newStateOpen);
31
- }
32
- useEffect(() => {
33
- if (props.defaultOpen) {
34
- set_open(props.defaultOpen);
35
- }
36
- setInitialized(true);
37
- }, []);
38
- useEffect(() => {
39
- if (_ref.current && initialized) {
40
- handleNameAttribute();
41
- }
42
- }, [_ref.current, initialized]);
43
- useEffect(() => {
44
- if (props.name) {
45
- set_name(props.name);
46
- }
47
- }, [props.name]);
48
- return (React.createElement("li", Object.assign({ id: (_a = props.id) !== null && _a !== void 0 ? _a : (_b = props.propOverrides) === null || _b === void 0 ? void 0 : _b.id }, getRootProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font", "data-density"]), { className: cls("db-accordion-item", props.className) }),
49
- React.createElement("details", Object.assign({ "aria-disabled": getBooleanAsString(props.disabled), ref: _ref }, filterPassingProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font", "data-density", "onToggle"]), { name: _name, open: _open }),
50
- React.createElement("summary", { onClick: (event) => handleToggle(event) },
51
- props.headlinePlain ? React.createElement(React.Fragment, null, props.headlinePlain) : null,
52
- !props.headlinePlain ? React.createElement(React.Fragment, null, props.headline) : null),
53
- React.createElement("div", null,
54
- props.text ? React.createElement(React.Fragment, null, props.text) : null,
55
- props.children))));
2
+ import { filterPassingProps as e, getRootProps as t } from "../../utils/react.js";
3
+ import { cls as n, getBoolean as r, getBooleanAsString as i } from "../../utils/index.js";
4
+ import { forwardRef as a, useEffect as o, useRef as s, useState as c } from "react";
5
+ import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
6
+ //#region src/components/accordion-item/accordion-item.tsx
7
+ function f(a, f) {
8
+ let p = f || s(f), [m, h] = c(() => !1), [g, _] = c(() => void 0), [v, y] = c(() => !1);
9
+ function b() {
10
+ if (p.current) {
11
+ let e = p.current.setAttribute;
12
+ p.current.setAttribute = (t, n) => {
13
+ e.call(p.current, t, n), t === "name" && _(n);
14
+ };
15
+ }
16
+ }
17
+ function x(e) {
18
+ e?.preventDefault();
19
+ let t = !m;
20
+ a.onToggle && a.onToggle(t), a.open === void 0 && h(t);
21
+ }
22
+ return o(() => {
23
+ a.defaultOpen && h(a.defaultOpen), y(!0);
24
+ }, []), o(() => {
25
+ p.current && v && b();
26
+ }, [p.current, v]), o(() => {
27
+ a.name && _(a.name);
28
+ }, [a.name]), o(() => {
29
+ let e = r(a.open, "open");
30
+ e !== void 0 && h(e);
31
+ }, [a.open]), /* @__PURE__ */ u("li", {
32
+ id: a.id ?? a.propOverrides?.id,
33
+ ...t(a, [
34
+ "data-icon-variant",
35
+ "data-icon-variant-before",
36
+ "data-icon-variant-after",
37
+ "data-icon-weight",
38
+ "data-icon-weight-before",
39
+ "data-icon-weight-after",
40
+ "data-interactive",
41
+ "data-force-mobile",
42
+ "data-color",
43
+ "data-container-color",
44
+ "data-bg-color",
45
+ "data-on-bg-color",
46
+ "data-color-scheme",
47
+ "data-font-size",
48
+ "data-headline-size",
49
+ "data-divider",
50
+ "data-focus",
51
+ "data-font",
52
+ "data-density"
53
+ ]),
54
+ className: n("db-accordion-item", a.className),
55
+ children: /* @__PURE__ */ d("details", {
56
+ "aria-disabled": i(a.disabled),
57
+ ref: p,
58
+ ...e(a, [
59
+ "data-icon-variant",
60
+ "data-icon-variant-before",
61
+ "data-icon-variant-after",
62
+ "data-icon-weight",
63
+ "data-icon-weight-before",
64
+ "data-icon-weight-after",
65
+ "data-interactive",
66
+ "data-force-mobile",
67
+ "data-color",
68
+ "data-container-color",
69
+ "data-bg-color",
70
+ "data-on-bg-color",
71
+ "data-color-scheme",
72
+ "data-font-size",
73
+ "data-headline-size",
74
+ "data-divider",
75
+ "data-focus",
76
+ "data-font",
77
+ "data-density",
78
+ "onToggle"
79
+ ]),
80
+ name: g,
81
+ open: m,
82
+ children: [/* @__PURE__ */ d("summary", {
83
+ onClick: (e) => x(e),
84
+ children: [a.headlinePlain ? /* @__PURE__ */ u(l, { children: a.headlinePlain }) : null, a.headlinePlain ? null : /* @__PURE__ */ u(l, { children: a.headline })]
85
+ }), /* @__PURE__ */ d("div", { children: [a.text ? /* @__PURE__ */ u(l, { children: a.text }) : null, a.children] })]
86
+ })
87
+ });
56
88
  }
57
- const DBAccordionItem = forwardRef(DBAccordionItemFn);
58
- export default DBAccordionItem;
89
+ var p = a(f);
90
+ //#endregion
91
+ export { p as default };
@@ -4,6 +4,10 @@ export type DBAccordionItemDefaultProps = {
4
4
  * Initial state for the accordion item
5
5
  */
6
6
  defaultOpen?: boolean;
7
+ /**
8
+ * State for the accordion item
9
+ */
10
+ open?: boolean | string;
7
11
  /**
8
12
  * The disabled attribute can be set to keep a user from clicking on the element.
9
13
  */