@dt-dds/react-accordion 1.0.0-beta.41

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,400 @@
1
+ # @dt-ui/react-accordion
2
+
3
+ ## 1.0.0-beta.41
4
+
5
+ ### Major Changes
6
+
7
+ - refactor!: rename pkg and publish to npmjs
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @dt-dds/react-core@1.0.0-beta.41
13
+ - @dt-dds/react-divider@1.0.0-beta.40
14
+ - @dt-dds/react-icon@1.0.0-beta.42
15
+
16
+ ## 0.1.0-beta.40
17
+
18
+ ### Patch Changes
19
+
20
+ - refactor: drop icon funcional state
21
+ - Updated dependencies
22
+ - @dt-ui/react-icon@0.1.0-beta.41
23
+
24
+ ## 0.1.0-beta.39
25
+
26
+ ### Patch Changes
27
+
28
+ - refactor: theme typography values
29
+ - Updated dependencies
30
+ - @dt-ui/react-core@0.1.0-beta.40
31
+ - @dt-ui/react-divider@0.1.0-beta.39
32
+ - @dt-ui/react-icon@0.1.0-beta.40
33
+
34
+ ## 0.1.0-beta.38
35
+
36
+ ### Minor Changes
37
+
38
+ - feat: update shadow theme values
39
+
40
+ ### Patch Changes
41
+
42
+ - Updated dependencies
43
+ - @dt-ui/react-core@0.1.0-beta.39
44
+ - @dt-ui/react-divider@0.1.0-beta.38
45
+ - @dt-ui/react-icon@0.1.0-beta.39
46
+
47
+ ## 0.1.0-beta.37
48
+
49
+ ### Minor Changes
50
+
51
+ - feat: add new icon font sizes
52
+
53
+ ### Patch Changes
54
+
55
+ - fix: change accordion export
56
+ - Updated dependencies
57
+ - @dt-ui/react-icon@0.1.0-beta.38
58
+
59
+ ## 0.1.0-beta.36
60
+
61
+ ### Patch Changes
62
+
63
+ - chore: update theme font-styles
64
+ - Updated dependencies
65
+ - @dt-ui/react-core@0.1.0-beta.38
66
+ - @dt-ui/react-divider@0.1.0-beta.37
67
+ - @dt-ui/react-icon@0.1.0-beta.37
68
+
69
+ ## 0.1.0-beta.35
70
+
71
+ ### Patch Changes
72
+
73
+ - chore: review OSS files
74
+ - Updated dependencies
75
+ - @dt-ui/react-core@0.1.0-beta.37
76
+ - @dt-ui/react-divider@0.1.0-beta.36
77
+ - @dt-ui/react-icon@0.1.0-beta.36
78
+
79
+ ## 0.1.0-beta.34
80
+
81
+ ### Patch Changes
82
+
83
+ - chore: update contextual colors
84
+ - Updated dependencies
85
+ - @dt-ui/react-core@0.1.0-beta.36
86
+ - @dt-ui/react-icon@0.1.0-beta.35
87
+ - @dt-ui/react-divider@0.1.0-beta.35
88
+
89
+ ## 0.1.0-beta.33
90
+
91
+ ### Minor Changes
92
+
93
+ - feat: implement accordion new UI
94
+
95
+ ## 0.1.0-beta.32
96
+
97
+ ### Patch Changes
98
+
99
+ - fix: change content.light contextual color
100
+ - Updated dependencies
101
+ - @dt-ui/react-core@0.1.0-beta.35
102
+ - @dt-ui/react-divider@0.1.0-beta.34
103
+
104
+ ## 0.1.0-beta.31
105
+
106
+ ### Patch Changes
107
+
108
+ - fix: add accent to colors type
109
+ - Updated dependencies
110
+ - @dt-ui/react-core@0.1.0-beta.34
111
+ - @dt-ui/react-divider@0.1.0-beta.33
112
+
113
+ ## 0.1.0-beta.30
114
+
115
+ ### Patch Changes
116
+
117
+ - fix: change button text according to ux
118
+ - Updated dependencies
119
+ - @dt-ui/react-core@0.1.0-beta.33
120
+ - @dt-ui/react-divider@0.1.0-beta.32
121
+
122
+ ## 0.1.0-beta.29
123
+
124
+ ### Patch Changes
125
+
126
+ - chore: update contexual colors
127
+ - Updated dependencies
128
+ - @dt-ui/react-core@0.1.0-beta.32
129
+ - @dt-ui/react-divider@0.1.0-beta.31
130
+
131
+ ## 0.1.0-beta.28
132
+
133
+ ### Patch Changes
134
+
135
+ - style: update responsive font styles
136
+ - Updated dependencies
137
+ - @dt-ui/react-core@0.1.0-beta.31
138
+ - @dt-ui/react-divider@0.1.0-beta.30
139
+
140
+ ## 0.1.0-beta.27
141
+
142
+ ### Minor Changes
143
+
144
+ - feat: add spinner size 'extra-small' & update specs
145
+
146
+ ### Patch Changes
147
+
148
+ - Updated dependencies
149
+ - @dt-ui/react-core@0.1.0-beta.30
150
+ - @dt-ui/react-divider@0.1.0-beta.29
151
+
152
+ ## 0.1.0-beta.26
153
+
154
+ ### Patch Changes
155
+
156
+ - chore: add theme breakpoints
157
+ - Updated dependencies
158
+ - @dt-ui/react-core@0.1.0-beta.29
159
+ - @dt-ui/react-divider@0.1.0-beta.28
160
+
161
+ ## 0.1.0-beta.25
162
+
163
+ ### Minor Changes
164
+
165
+ - feat: add id to base props
166
+
167
+ ### Patch Changes
168
+
169
+ - Updated dependencies
170
+ - @dt-ui/react-core@0.1.0-beta.28
171
+ - @dt-ui/react-divider@0.1.0-beta.27
172
+
173
+ ## 0.1.0-beta.24
174
+
175
+ ### Minor Changes
176
+
177
+ - feat: change breakpoints values
178
+
179
+ ### Patch Changes
180
+
181
+ - Updated dependencies
182
+ - @dt-ui/react-core@0.1.0-beta.27
183
+ - @dt-ui/react-divider@0.1.0-beta.26
184
+
185
+ ## 0.1.0-beta.23
186
+
187
+ ### Patch Changes
188
+
189
+ - fix: replace body to correct one
190
+ - Updated dependencies
191
+ - @dt-ui/react-core@0.1.0-beta.26
192
+ - @dt-ui/react-divider@0.1.0-beta.25
193
+
194
+ ## 0.1.0-beta.22
195
+
196
+ ### Patch Changes
197
+
198
+ - chore: add theme colors missing types
199
+ - Updated dependencies
200
+ - @dt-ui/react-core@0.1.0-beta.25
201
+ - @dt-ui/react-divider@0.1.0-beta.24
202
+
203
+ ## 0.1.0-beta.21
204
+
205
+ ### Patch Changes
206
+
207
+ - refactor: drop truckapi theme
208
+ - Updated dependencies
209
+ - @dt-ui/react-core@0.1.0-beta.24
210
+ - @dt-ui/react-divider@0.1.0-beta.23
211
+
212
+ ## 0.1.0-beta.20
213
+
214
+ ### Patch Changes
215
+
216
+ - fix: update Accordion styles
217
+
218
+ ## 0.1.0-beta.19
219
+
220
+ ### Minor Changes
221
+
222
+ - feat: update core and semantic colors
223
+ - feat: remove greenlane theme
224
+
225
+ ### Patch Changes
226
+
227
+ - Updated dependencies
228
+ - Updated dependencies
229
+ - @dt-ui/react-core@0.1.0-beta.23
230
+ - @dt-ui/react-divider@0.1.0-beta.22
231
+
232
+ ## 0.1.0-beta.18
233
+
234
+ ### Minor Changes
235
+
236
+ - feat: add icon option for truckapi theme
237
+
238
+ ### Patch Changes
239
+
240
+ - Updated dependencies
241
+ - @dt-ui/react-core@0.1.0-beta.22
242
+ - @dt-ui/react-divider@0.1.0-beta.21
243
+
244
+ ## 0.1.0-beta.17
245
+
246
+ ### Patch Changes
247
+
248
+ - fix: tooltip z index
249
+ - Updated dependencies
250
+ - @dt-ui/react-core@0.1.0-beta.21
251
+ - @dt-ui/react-divider@0.1.0-beta.20
252
+
253
+ ## 0.1.0-beta.16
254
+
255
+ ### Minor Changes
256
+
257
+ - feat: add segmented control component
258
+
259
+ ### Patch Changes
260
+
261
+ - Updated dependencies
262
+ - @dt-ui/react-core@0.1.0-beta.20
263
+ - @dt-ui/react-divider@0.1.0-beta.19
264
+
265
+ ## 0.1.0-beta.15
266
+
267
+ ### Patch Changes
268
+
269
+ - fix: add shape for tooltip on truckapi theme
270
+ - Updated dependencies
271
+ - @dt-ui/react-core@0.1.0-beta.19
272
+ - @dt-ui/react-divider@0.1.0-beta.18
273
+
274
+ ## 0.1.0-beta.14
275
+
276
+ ### Patch Changes
277
+
278
+ - fix: remove devDependecy export
279
+ - Updated dependencies
280
+ - @dt-ui/react-core@0.1.0-beta.18
281
+ - @dt-ui/react-divider@0.1.0-beta.17
282
+
283
+ ## 0.1.0-beta.13
284
+
285
+ ### Patch Changes
286
+
287
+ - test: add test custom render
288
+ - Updated dependencies
289
+ - @dt-ui/react-core@0.1.0-beta.17
290
+ - @dt-ui/react-divider@0.1.0-beta.16
291
+
292
+ ## 0.1.0-beta.12
293
+
294
+ ### Minor Changes
295
+
296
+ - feat: create select
297
+
298
+ ### Patch Changes
299
+
300
+ - Updated dependencies
301
+ - @dt-ui/react-core@0.1.0-beta.16
302
+ - @dt-ui/react-divider@0.1.0-beta.15
303
+
304
+ ## 0.1.0-beta.11
305
+
306
+ ### Patch Changes
307
+
308
+ - fix: show shadows only when scroll is visible
309
+ - Updated dependencies
310
+ - @dt-ui/react-core@0.1.0-beta.15
311
+ - @dt-ui/react-divider@0.1.0-beta.14
312
+
313
+ ## 0.1.0-beta.10
314
+
315
+ ### Patch Changes
316
+
317
+ - fix: update border radius theme specifications
318
+ - Updated dependencies
319
+ - @dt-ui/react-core@0.1.0-beta.14
320
+ - @dt-ui/react-divider@0.1.0-beta.13
321
+
322
+ ## 0.1.0-beta.9
323
+
324
+ ### Patch Changes
325
+
326
+ - fix: match accordion design
327
+ - Updated dependencies
328
+ - @dt-ui/react-core@0.1.0-beta.13
329
+ - @dt-ui/react-divider@0.1.0-beta.12
330
+
331
+ ## 0.1.0-beta.8
332
+
333
+ ### Patch Changes
334
+
335
+ - fix: make icons an optional property in theme
336
+ - Updated dependencies
337
+ - @dt-ui/react-core@0.1.0-beta.12
338
+ - @dt-ui/react-divider@0.1.0-beta.11
339
+
340
+ ## 0.1.0-beta.7
341
+
342
+ ### Patch Changes
343
+
344
+ - refactor: extract text-field to new package with greenlane theme
345
+ - Updated dependencies
346
+ - @dt-ui/react-core@0.1.0-beta.11
347
+ - @dt-ui/react-divider@0.1.0-beta.10
348
+
349
+ ## 0.1.0-beta.6
350
+
351
+ ### Patch Changes
352
+
353
+ - refactor: move and refactor checkbox refactor checkbox according to design
354
+ - Updated dependencies
355
+ - @dt-ui/react-core@0.1.0-beta.10
356
+ - @dt-ui/react-divider@0.1.0-beta.9
357
+
358
+ ## 0.1.0-beta.5
359
+
360
+ ### Patch Changes
361
+
362
+ - fix(icons): export css and update imports on deps
363
+ - Updated dependencies
364
+ - @dt-ui/react-core@0.1.0-beta.9
365
+ - @dt-ui/react-divider@0.1.0-beta.8
366
+
367
+ ## 0.1.0-beta.4
368
+
369
+ ### Patch Changes
370
+
371
+ - chore: update component generator and lint fixes
372
+ - Updated dependencies
373
+ - @dt-ui/react-divider@0.1.0-beta.7
374
+
375
+ ## 0.1.0-beta.3
376
+
377
+ ### Patch Changes
378
+
379
+ - chore: move util functions to the core
380
+ - Updated dependencies
381
+ - @dt-ui/react-core@0.1.0-beta.8
382
+ - @dt-ui/react-divider@0.1.0-beta.6
383
+
384
+ ## 0.1.0-beta.2
385
+
386
+ ### Minor Changes
387
+
388
+ - feat: add contextual color add content tertiary to palette
389
+
390
+ ### Patch Changes
391
+
392
+ - Updated dependencies
393
+ - @dt-ui/react-core@0.1.0-beta.7
394
+ - @dt-ui/react-divider@0.1.0-beta.5
395
+
396
+ ## 0.1.0-beta.1
397
+
398
+ ### Minor Changes
399
+
400
+ - feat: accordion component
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Daimler Truck AG.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Accordion Package
2
+
3
+ An accordion is a vertically stacked list of headers that reveal or hide associated sections of content.
4
+
5
+ ## Accordion Usage
6
+
7
+ ```jsx
8
+ import { Accordion } from '@dt-dds/react';
9
+
10
+ export const App = () => {
11
+ const headerCustomContent = <>Header content here.</>;
12
+
13
+ return (
14
+ <Accordion headerContent={headerCustomContent}>
15
+ Body content here.
16
+ </Accordion>
17
+ );
18
+ };
19
+ ```
20
+
21
+ ## Properties
22
+
23
+ | Property | Type | Default | Description |
24
+ | ----------------- | --------------------- | ------------------- | ----------------------------------------------------------- |
25
+ | `isOpen` | `boolean` | false | Boolean value to define if the accordion is open or closed |
26
+ | `hasBackground` | `boolean` | false | Sets the Accordion background color |
27
+ | `headerContent` | `ReactNode` | - | Child component to be rendered on the accordion header |
28
+ | `isDisabled` | `boolean` | false | Boolean value to define if the Accordion is disabled or not |
29
+ | `children` | `ReactNode` | - | Child component to be rendered on the accordion body |
30
+ | `dataTestId` | `string` | accordion-container | Accordion test identifier |
31
+ | `style` | `React.CSSProperties` | - | Gives the Accordion CSS properties |
32
+ | `hasBorderBottom` | `boolean` | false | Sets the Accordion border-bottom |
33
+
34
+ ### Stack
35
+
36
+ - [TypeScript](https://www.typescriptlang.org/) for static type checking
37
+ - [React](https://reactjs.org/) — JavaScript library for user interfaces
38
+ - [Emotion](https://emotion.sh/docs/introduction) — for writing css styles with JavaScript
39
+ - [Storybook](https://storybook.js.org/) — UI component environment powered by Vite
40
+ - [Jest](https://jestjs.io/) - JavaScript Testing Framework
41
+ - [React Testing Library](https://testing-library.com/) - to test UI components in a user-centric way
42
+ - [ESLint](https://eslint.org/) for code linting
43
+ - [Prettier](https://prettier.io) for code formatting
44
+ - [Tsup](https://github.com/egoist/tsup) — TypeScript bundler powered by esbuild
45
+ - [Yarn](https://yarnpkg.com/) from managing packages
46
+
47
+ ### Commands
48
+
49
+ - `yarn build` - Build the package
50
+ - `yarn dev` - Run the package locally
51
+ - `yarn lint` - Lint all files within this package
52
+ - `yarn test` - Run all unit tests
53
+ - `yarn test:report` - Open the test coverage report
54
+ - `yarn test:update:snapshot` - Run all unit tests and update the snapshot
55
+
56
+ ### Compilation
57
+
58
+ Running `yarn build` from the root of the package will use [tsup](https://tsup.egoist.dev/) to compile the raw TypeScript and React code to plain JavaScript.
59
+
60
+ The `/dist` folder contains the compiled output.
61
+
62
+ ```bash
63
+ accordion
64
+ └── dist
65
+ ├── index.d.ts <-- Types
66
+ ├── index.js <-- CommonJS version
67
+ └── index.mjs <-- ES Modules version
68
+ ...
69
+ ```
70
+
71
+ ### Versioning
72
+
73
+ Follows [semantic versioning](https://semver.org/)
74
+
75
+ ## &copy; License
76
+
77
+ Licensed under [MIT License](LICENSE.md)
@@ -0,0 +1,20 @@
1
+ import { BaseProps, Theme } from '@dt-dds/react-core';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { ReactNode } from 'react';
4
+
5
+ interface AccordionBaseProps extends BaseProps {
6
+ isOpen?: boolean;
7
+ headerContent: ReactNode;
8
+ hasBackground?: boolean;
9
+ isDisabled?: boolean;
10
+ hasBorderBottom?: boolean;
11
+ className?: string;
12
+ }
13
+ declare const Accordion: ({ isOpen, headerContent, hasBackground, hasBorderBottom, isDisabled, children, dataTestId, style, className, }: AccordionBaseProps) => react_jsx_runtime.JSX.Element;
14
+
15
+ declare module '@emotion/react' {
16
+ interface Theme extends Theme {
17
+ }
18
+ }
19
+
20
+ export { Accordion, AccordionBaseProps };
package/dist/index.js ADDED
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // index.ts
31
+ var accordion_exports = {};
32
+ __export(accordion_exports, {
33
+ Accordion: () => Accordion
34
+ });
35
+ module.exports = __toCommonJS(accordion_exports);
36
+
37
+ // src/Accordion.tsx
38
+ var import_react2 = require("react");
39
+
40
+ // src/Accordion.styled.ts
41
+ var import_styled = __toESM(require("@emotion/styled"));
42
+ var AccordionStyled = import_styled.default.div`
43
+ ${({ theme, hasBackground, isDisabled, hasBorderBottom }) => `
44
+ position: relative;
45
+ width: 100%;
46
+ background-color: ${hasBackground ? theme.palette.surface.light : "transparent"};
47
+ border-bottom: ${hasBorderBottom ? `1px solid ${theme.palette.border.default}` : "none"};
48
+
49
+ ${isDisabled ? `
50
+ background-color: ${theme.palette.surface.light};
51
+ color: ${theme.palette.content.light};
52
+
53
+ * {
54
+ cursor: not-allowed;
55
+ user-select: none;
56
+ color: inherit;
57
+ }
58
+ ` : `
59
+ &:hover {
60
+ background-color: ${theme.palette.surface.default};
61
+ box-shadow: ${theme.shadows.xs};
62
+ }
63
+ `}
64
+ `}
65
+ `;
66
+
67
+ // src/components/header/AccordionHeader.tsx
68
+ var import_react_icon = require("@dt-dds/react-icon");
69
+ var import_react = require("@emotion/react");
70
+
71
+ // src/components/header/AccordionHeader.styled.ts
72
+ var import_styled2 = __toESM(require("@emotion/styled"));
73
+ var HeaderStyled = import_styled2.default.header`
74
+ ${({ theme }) => `
75
+ ${theme.fontStyles.h6};
76
+ display: flex;
77
+ align-items: center;
78
+ justify-content: space-between;
79
+ gap: ${theme.spacing["4xs"]};
80
+ padding: ${theme.spacing["2xs"]};
81
+ cursor: pointer;
82
+ user-select: none;
83
+ color: ${theme.palette.surface.dark};
84
+
85
+ &:focus-visible {
86
+ outline: 2px solid ${theme.palette.primary.default};
87
+ }
88
+ `}
89
+ `;
90
+
91
+ // src/components/header/AccordionHeader.tsx
92
+ var import_jsx_runtime = require("react/jsx-runtime");
93
+ var AccordionHeader = ({
94
+ handleHeaderClick,
95
+ handleHeaderKeyPress,
96
+ isOpenState,
97
+ isDisabled,
98
+ children,
99
+ dataTestId,
100
+ style
101
+ }) => {
102
+ const theme = (0, import_react.useTheme)();
103
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
104
+ HeaderStyled,
105
+ {
106
+ "aria-disabled": isDisabled,
107
+ "data-testid": dataTestId != null ? dataTestId : "accordion-header",
108
+ onClick: handleHeaderClick,
109
+ onKeyDown: handleHeaderKeyPress,
110
+ role: "button",
111
+ style,
112
+ tabIndex: isDisabled ? -1 : 0,
113
+ children: [
114
+ children,
115
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
116
+ import_react_icon.Icon,
117
+ {
118
+ code: isOpenState ? "unfold_less" : "unfold_more",
119
+ color: theme.palette.content.dark,
120
+ size: "l"
121
+ }
122
+ )
123
+ ]
124
+ }
125
+ );
126
+ };
127
+
128
+ // src/components/body/AccordionBody.styled.ts
129
+ var import_styled3 = __toESM(require("@emotion/styled"));
130
+ var BodyStyled = import_styled3.default.div`
131
+ ${({ theme, isOpenState }) => `
132
+ ${theme.fontStyles.body1};
133
+ display: grid;
134
+ grid-template-rows: ${isOpenState ? "1fr" : "0fr"};
135
+ transition: grid-template-rows 0.3s ease-in-out, padding 0.3s ease-in-out;
136
+ color: ${theme.palette.content.dark};
137
+
138
+ padding: 0 ${theme.spacing["2xs"]} ${isOpenState ? theme.spacing["2xs"] : 0};
139
+
140
+ & > div {
141
+ width: 100%;
142
+ height: 100%;
143
+ overflow: hidden;
144
+ }
145
+ `}
146
+ `;
147
+
148
+ // src/components/body/AccordionBody.tsx
149
+ var import_jsx_runtime2 = require("react/jsx-runtime");
150
+ var AccordionBody = ({
151
+ isOpenState,
152
+ children,
153
+ dataTestId,
154
+ style
155
+ }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
156
+ BodyStyled,
157
+ {
158
+ "aria-expanded": isOpenState,
159
+ "data-testid": dataTestId != null ? dataTestId : "accordion-body",
160
+ isOpenState,
161
+ style,
162
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children })
163
+ }
164
+ );
165
+
166
+ // src/Accordion.tsx
167
+ var import_jsx_runtime3 = require("react/jsx-runtime");
168
+ var Accordion = ({
169
+ isOpen = false,
170
+ headerContent,
171
+ hasBackground = true,
172
+ hasBorderBottom = false,
173
+ isDisabled = false,
174
+ children,
175
+ dataTestId,
176
+ style,
177
+ className
178
+ }) => {
179
+ const [isOpenState, setIsOpenState] = (0, import_react2.useState)(isOpen);
180
+ const handleHeaderClick = () => {
181
+ if (isDisabled) {
182
+ return;
183
+ }
184
+ setIsOpenState((prev) => !prev);
185
+ };
186
+ const handleHeaderKeyPress = (event) => {
187
+ if (event.key === "Enter") {
188
+ handleHeaderClick();
189
+ }
190
+ };
191
+ (0, import_react2.useEffect)(() => {
192
+ setIsOpenState(isOpen);
193
+ }, [isOpen]);
194
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
195
+ AccordionStyled,
196
+ {
197
+ className,
198
+ "data-testid": dataTestId != null ? dataTestId : "accordion-container",
199
+ hasBackground,
200
+ hasBorderBottom,
201
+ isDisabled,
202
+ style,
203
+ children: [
204
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
205
+ AccordionHeader,
206
+ {
207
+ handleHeaderClick,
208
+ handleHeaderKeyPress,
209
+ isDisabled,
210
+ isOpenState,
211
+ children: headerContent
212
+ }
213
+ ),
214
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AccordionBody, { isOpenState, children })
215
+ ]
216
+ }
217
+ );
218
+ };
219
+ // Annotate the CommonJS export names for ESM import in node:
220
+ 0 && (module.exports = {
221
+ Accordion
222
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,185 @@
1
+ // src/Accordion.tsx
2
+ import { useEffect, useState } from "react";
3
+
4
+ // src/Accordion.styled.ts
5
+ import styled from "@emotion/styled";
6
+ var AccordionStyled = styled.div`
7
+ ${({ theme, hasBackground, isDisabled, hasBorderBottom }) => `
8
+ position: relative;
9
+ width: 100%;
10
+ background-color: ${hasBackground ? theme.palette.surface.light : "transparent"};
11
+ border-bottom: ${hasBorderBottom ? `1px solid ${theme.palette.border.default}` : "none"};
12
+
13
+ ${isDisabled ? `
14
+ background-color: ${theme.palette.surface.light};
15
+ color: ${theme.palette.content.light};
16
+
17
+ * {
18
+ cursor: not-allowed;
19
+ user-select: none;
20
+ color: inherit;
21
+ }
22
+ ` : `
23
+ &:hover {
24
+ background-color: ${theme.palette.surface.default};
25
+ box-shadow: ${theme.shadows.xs};
26
+ }
27
+ `}
28
+ `}
29
+ `;
30
+
31
+ // src/components/header/AccordionHeader.tsx
32
+ import { Icon } from "@dt-dds/react-icon";
33
+ import { useTheme } from "@emotion/react";
34
+
35
+ // src/components/header/AccordionHeader.styled.ts
36
+ import styled2 from "@emotion/styled";
37
+ var HeaderStyled = styled2.header`
38
+ ${({ theme }) => `
39
+ ${theme.fontStyles.h6};
40
+ display: flex;
41
+ align-items: center;
42
+ justify-content: space-between;
43
+ gap: ${theme.spacing["4xs"]};
44
+ padding: ${theme.spacing["2xs"]};
45
+ cursor: pointer;
46
+ user-select: none;
47
+ color: ${theme.palette.surface.dark};
48
+
49
+ &:focus-visible {
50
+ outline: 2px solid ${theme.palette.primary.default};
51
+ }
52
+ `}
53
+ `;
54
+
55
+ // src/components/header/AccordionHeader.tsx
56
+ import { jsx, jsxs } from "react/jsx-runtime";
57
+ var AccordionHeader = ({
58
+ handleHeaderClick,
59
+ handleHeaderKeyPress,
60
+ isOpenState,
61
+ isDisabled,
62
+ children,
63
+ dataTestId,
64
+ style
65
+ }) => {
66
+ const theme = useTheme();
67
+ return /* @__PURE__ */ jsxs(
68
+ HeaderStyled,
69
+ {
70
+ "aria-disabled": isDisabled,
71
+ "data-testid": dataTestId != null ? dataTestId : "accordion-header",
72
+ onClick: handleHeaderClick,
73
+ onKeyDown: handleHeaderKeyPress,
74
+ role: "button",
75
+ style,
76
+ tabIndex: isDisabled ? -1 : 0,
77
+ children: [
78
+ children,
79
+ /* @__PURE__ */ jsx(
80
+ Icon,
81
+ {
82
+ code: isOpenState ? "unfold_less" : "unfold_more",
83
+ color: theme.palette.content.dark,
84
+ size: "l"
85
+ }
86
+ )
87
+ ]
88
+ }
89
+ );
90
+ };
91
+
92
+ // src/components/body/AccordionBody.styled.ts
93
+ import styled3 from "@emotion/styled";
94
+ var BodyStyled = styled3.div`
95
+ ${({ theme, isOpenState }) => `
96
+ ${theme.fontStyles.body1};
97
+ display: grid;
98
+ grid-template-rows: ${isOpenState ? "1fr" : "0fr"};
99
+ transition: grid-template-rows 0.3s ease-in-out, padding 0.3s ease-in-out;
100
+ color: ${theme.palette.content.dark};
101
+
102
+ padding: 0 ${theme.spacing["2xs"]} ${isOpenState ? theme.spacing["2xs"] : 0};
103
+
104
+ & > div {
105
+ width: 100%;
106
+ height: 100%;
107
+ overflow: hidden;
108
+ }
109
+ `}
110
+ `;
111
+
112
+ // src/components/body/AccordionBody.tsx
113
+ import { jsx as jsx2 } from "react/jsx-runtime";
114
+ var AccordionBody = ({
115
+ isOpenState,
116
+ children,
117
+ dataTestId,
118
+ style
119
+ }) => /* @__PURE__ */ jsx2(
120
+ BodyStyled,
121
+ {
122
+ "aria-expanded": isOpenState,
123
+ "data-testid": dataTestId != null ? dataTestId : "accordion-body",
124
+ isOpenState,
125
+ style,
126
+ children: /* @__PURE__ */ jsx2("div", { children })
127
+ }
128
+ );
129
+
130
+ // src/Accordion.tsx
131
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
132
+ var Accordion = ({
133
+ isOpen = false,
134
+ headerContent,
135
+ hasBackground = true,
136
+ hasBorderBottom = false,
137
+ isDisabled = false,
138
+ children,
139
+ dataTestId,
140
+ style,
141
+ className
142
+ }) => {
143
+ const [isOpenState, setIsOpenState] = useState(isOpen);
144
+ const handleHeaderClick = () => {
145
+ if (isDisabled) {
146
+ return;
147
+ }
148
+ setIsOpenState((prev) => !prev);
149
+ };
150
+ const handleHeaderKeyPress = (event) => {
151
+ if (event.key === "Enter") {
152
+ handleHeaderClick();
153
+ }
154
+ };
155
+ useEffect(() => {
156
+ setIsOpenState(isOpen);
157
+ }, [isOpen]);
158
+ return /* @__PURE__ */ jsxs2(
159
+ AccordionStyled,
160
+ {
161
+ className,
162
+ "data-testid": dataTestId != null ? dataTestId : "accordion-container",
163
+ hasBackground,
164
+ hasBorderBottom,
165
+ isDisabled,
166
+ style,
167
+ children: [
168
+ /* @__PURE__ */ jsx3(
169
+ AccordionHeader,
170
+ {
171
+ handleHeaderClick,
172
+ handleHeaderKeyPress,
173
+ isDisabled,
174
+ isOpenState,
175
+ children: headerContent
176
+ }
177
+ ),
178
+ /* @__PURE__ */ jsx3(AccordionBody, { isOpenState, children })
179
+ ]
180
+ }
181
+ );
182
+ };
183
+ export {
184
+ Accordion
185
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@dt-dds/react-accordion",
3
+ "version": "1.0.0-beta.41",
4
+ "license": "MIT",
5
+ "exports": {
6
+ ".": "./dist/index.js"
7
+ },
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "files": [
12
+ "dist/**"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsup",
16
+ "dev": "tsup --watch",
17
+ "lint": "eslint --cache .",
18
+ "test": "jest",
19
+ "test:report": "open ./jest-coverage/lcov-report/index.html",
20
+ "test:update:snapshot": "jest -u"
21
+ },
22
+ "dependencies": {
23
+ "@dt-dds/react-core": "1.0.0-beta.41",
24
+ "@dt-dds/react-divider": "1.0.0-beta.40",
25
+ "@dt-dds/react-icon": "1.0.0-beta.42"
26
+ },
27
+ "devDependencies": {
28
+ "@babel/core": "^7.22.9",
29
+ "@babel/preset-env": "^7.22.9",
30
+ "@babel/preset-react": "^7.22.5",
31
+ "@babel/preset-typescript": "^7.23.3",
32
+ "@emotion/babel-plugin": "^11.11.0",
33
+ "@emotion/css": "^11.7.1",
34
+ "@emotion/jest": "^11.10.0",
35
+ "@emotion/react": "^11.8.2",
36
+ "@emotion/styled": "^11.8.1",
37
+ "@types/react": "^18.0.9",
38
+ "@types/react-dom": "^18.0.4",
39
+ "babel-loader": "^8.3.0",
40
+ "eslint-config-custom": "*",
41
+ "eslint-plugin-storybook": "^9.1.0",
42
+ "jest-config": "*",
43
+ "react": "^18.1.0",
44
+ "react-dom": "^18.2.0",
45
+ "tsconfig": "*",
46
+ "tsup": "^6.6.3",
47
+ "typescript": "^4.5.3"
48
+ },
49
+ "peerDependencies": {
50
+ "@emotion/css": "^11.7.1",
51
+ "@emotion/react": "^11.8.2",
52
+ "@emotion/styled": "^11.8.1",
53
+ "react": ">=17.0.2",
54
+ "react-dom": ">=17.0.2"
55
+ }
56
+ }