@dt-dds/react-checkbox 1.0.0-beta.40

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,389 @@
1
+ # @dt-ui/react-checkbox
2
+
3
+ ## 1.0.0-beta.40
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-icon@1.0.0-beta.42
14
+
15
+ ## 0.1.0-beta.39
16
+
17
+ ### Patch Changes
18
+
19
+ - refactor: drop icon funcional state
20
+ - Updated dependencies
21
+ - @dt-ui/react-icon@0.1.0-beta.41
22
+
23
+ ## 0.1.0-beta.38
24
+
25
+ ### Patch Changes
26
+
27
+ - refactor: theme typography values
28
+ - Updated dependencies
29
+ - @dt-ui/react-core@0.1.0-beta.40
30
+ - @dt-ui/react-icon@0.1.0-beta.40
31
+
32
+ ## 0.1.0-beta.37
33
+
34
+ ### Minor Changes
35
+
36
+ - feat: update shadow theme values
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies
41
+ - @dt-ui/react-core@0.1.0-beta.39
42
+ - @dt-ui/react-icon@0.1.0-beta.39
43
+
44
+ ## 0.1.0-beta.36
45
+
46
+ ### Minor Changes
47
+
48
+ - feat: add new icon font sizes
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies
53
+ - @dt-ui/react-icon@0.1.0-beta.38
54
+
55
+ ## 0.1.0-beta.35
56
+
57
+ ### Patch Changes
58
+
59
+ - chore: update theme font-styles
60
+ - Updated dependencies
61
+ - @dt-ui/react-core@0.1.0-beta.38
62
+ - @dt-ui/react-icon@0.1.0-beta.37
63
+
64
+ ## 0.1.0-beta.34
65
+
66
+ ### Patch Changes
67
+
68
+ - chore: review OSS files
69
+ - Updated dependencies
70
+ - @dt-ui/react-core@0.1.0-beta.37
71
+ - @dt-ui/react-icon@0.1.0-beta.36
72
+
73
+ ## 0.1.0-beta.33
74
+
75
+ ### Patch Changes
76
+
77
+ - chore: update contextual colors
78
+ - Updated dependencies
79
+ - @dt-ui/react-core@0.1.0-beta.36
80
+ - @dt-ui/react-icon@0.1.0-beta.35
81
+
82
+ ## 0.1.0-beta.32
83
+
84
+ ### Minor Changes
85
+
86
+ - feat: implement IconButton contrast and size
87
+
88
+ ### Patch Changes
89
+
90
+ - Updated dependencies
91
+ - @dt-ui/react-icon@0.1.0-beta.34
92
+
93
+ ## 0.1.0-beta.31
94
+
95
+ ### Patch Changes
96
+
97
+ - fix: change content.light contextual color
98
+ - Updated dependencies
99
+ - @dt-ui/react-core@0.1.0-beta.35
100
+ - @dt-ui/react-icon@0.1.0-beta.33
101
+
102
+ ## 0.1.0-beta.30
103
+
104
+ ### Minor Changes
105
+
106
+ - feat: move icon-button to independent
107
+
108
+ ### Patch Changes
109
+
110
+ - Updated dependencies
111
+ - @dt-ui/react-icon@0.1.0-beta.32
112
+
113
+ ## 0.1.0-beta.29
114
+
115
+ ### Patch Changes
116
+
117
+ - fix: add accent to colors type
118
+ - Updated dependencies
119
+ - @dt-ui/react-core@0.1.0-beta.34
120
+ - @dt-ui/react-icon@0.1.0-beta.31
121
+
122
+ ## 0.1.0-beta.28
123
+
124
+ ### Patch Changes
125
+
126
+ - fix: change button text according to ux
127
+ - Updated dependencies
128
+ - @dt-ui/react-core@0.1.0-beta.33
129
+ - @dt-ui/react-icon@0.1.0-beta.30
130
+
131
+ ## 0.1.0-beta.27
132
+
133
+ ### Patch Changes
134
+
135
+ - fix: checkbox style
136
+
137
+ ## 0.1.0-beta.26
138
+
139
+ ### Patch Changes
140
+
141
+ - chore: update contexual colors
142
+ - Updated dependencies
143
+ - @dt-ui/react-core@0.1.0-beta.32
144
+ - @dt-ui/react-icon@0.1.0-beta.29
145
+
146
+ ## 0.1.0-beta.25
147
+
148
+ ### Patch Changes
149
+
150
+ - style: update responsive font styles
151
+ - Updated dependencies
152
+ - @dt-ui/react-core@0.1.0-beta.31
153
+ - @dt-ui/react-icon@0.1.0-beta.28
154
+
155
+ ## 0.1.0-beta.24
156
+
157
+ ### Minor Changes
158
+
159
+ - feat: add spinner size 'extra-small' & update specs
160
+
161
+ ### Patch Changes
162
+
163
+ - Updated dependencies
164
+ - @dt-ui/react-core@0.1.0-beta.30
165
+ - @dt-ui/react-icon@0.1.0-beta.27
166
+
167
+ ## 0.1.0-beta.23
168
+
169
+ ### Patch Changes
170
+
171
+ - chore: add theme breakpoints
172
+ - Updated dependencies
173
+ - @dt-ui/react-core@0.1.0-beta.29
174
+ - @dt-ui/react-icon@0.1.0-beta.26
175
+
176
+ ## 0.1.0-beta.22
177
+
178
+ ### Minor Changes
179
+
180
+ - feat: add id to base props
181
+
182
+ ### Patch Changes
183
+
184
+ - Updated dependencies
185
+ - @dt-ui/react-core@0.1.0-beta.28
186
+ - @dt-ui/react-icon@0.1.0-beta.25
187
+
188
+ ## 0.1.0-beta.21
189
+
190
+ ### Minor Changes
191
+
192
+ - feat: change breakpoints values
193
+
194
+ ### Patch Changes
195
+
196
+ - Updated dependencies
197
+ - @dt-ui/react-core@0.1.0-beta.27
198
+ - @dt-ui/react-icon@0.1.0-beta.24
199
+
200
+ ## 0.1.0-beta.20
201
+
202
+ ### Patch Changes
203
+
204
+ - fix: replace body to correct one
205
+ - Updated dependencies
206
+ - @dt-ui/react-core@0.1.0-beta.26
207
+ - @dt-ui/react-icon@0.1.0-beta.23
208
+
209
+ ## 0.1.0-beta.19
210
+
211
+ ### Patch Changes
212
+
213
+ - chore: add theme colors missing types
214
+ - Updated dependencies
215
+ - @dt-ui/react-core@0.1.0-beta.25
216
+ - @dt-ui/react-icon@0.1.0-beta.22
217
+
218
+ ## 0.1.0-beta.18
219
+
220
+ ### Patch Changes
221
+
222
+ - refactor: drop truckapi theme
223
+ - Updated dependencies
224
+ - @dt-ui/react-core@0.1.0-beta.24
225
+ - @dt-ui/react-icon@0.1.0-beta.21
226
+
227
+ ## 0.1.0-beta.17
228
+
229
+ ### Minor Changes
230
+
231
+ - feat: update core and semantic colors
232
+ - feat: remove greenlane theme
233
+
234
+ ### Patch Changes
235
+
236
+ - Updated dependencies
237
+ - Updated dependencies
238
+ - @dt-ui/react-core@0.1.0-beta.23
239
+ - @dt-ui/react-icon@0.1.0-beta.20
240
+
241
+ ## 0.1.0-beta.16
242
+
243
+ ### Minor Changes
244
+
245
+ - feat: add icon option for truckapi theme
246
+
247
+ ### Patch Changes
248
+
249
+ - Updated dependencies
250
+ - @dt-ui/react-core@0.1.0-beta.22
251
+ - @dt-ui/react-icon@0.1.0-beta.19
252
+
253
+ ## 0.1.0-beta.15
254
+
255
+ ### Patch Changes
256
+
257
+ - fix: tooltip z index
258
+ - Updated dependencies
259
+ - @dt-ui/react-core@0.1.0-beta.21
260
+ - @dt-ui/react-icon@0.1.0-beta.18
261
+
262
+ ## 0.1.0-beta.14
263
+
264
+ ### Minor Changes
265
+
266
+ - feat: add segmented control component
267
+
268
+ ### Patch Changes
269
+
270
+ - Updated dependencies
271
+ - @dt-ui/react-core@0.1.0-beta.20
272
+ - @dt-ui/react-icon@0.1.0-beta.17
273
+
274
+ ## 0.1.0-beta.13
275
+
276
+ ### Patch Changes
277
+
278
+ - fix: add shape for tooltip on truckapi theme
279
+ - Updated dependencies
280
+ - @dt-ui/react-core@0.1.0-beta.19
281
+ - @dt-ui/react-icon@0.1.0-beta.16
282
+
283
+ ## 0.1.0-beta.12
284
+
285
+ ### Patch Changes
286
+
287
+ - fix: remove devDependecy export
288
+ - Updated dependencies
289
+ - @dt-ui/react-core@0.1.0-beta.18
290
+ - @dt-ui/react-icon@0.1.0-beta.15
291
+
292
+ ## 0.1.0-beta.11
293
+
294
+ ### Patch Changes
295
+
296
+ - test: add test custom render
297
+ - Updated dependencies
298
+ - @dt-ui/react-core@0.1.0-beta.17
299
+ - @dt-ui/react-icon@0.1.0-beta.14
300
+
301
+ ## 0.1.0-beta.10
302
+
303
+ ### Patch Changes
304
+
305
+ - fix: checkbox forwardRef needs ref as second param
306
+
307
+ ## 0.1.0-beta.9
308
+
309
+ ### Minor Changes
310
+
311
+ - feat: add input props to checkbox
312
+
313
+ ## 0.1.0-beta.8
314
+
315
+ ### Minor Changes
316
+
317
+ - feat: create select
318
+ - feat: add checkboxId and value to checkbox
319
+
320
+ ### Patch Changes
321
+
322
+ - Updated dependencies
323
+ - @dt-ui/react-core@0.1.0-beta.16
324
+ - @dt-ui/react-icon@0.1.0-beta.13
325
+
326
+ ## 0.1.0-beta.7
327
+
328
+ ### Patch Changes
329
+
330
+ - fix: show shadows only when scroll is visible
331
+ - Updated dependencies
332
+ - @dt-ui/react-core@0.1.0-beta.15
333
+ - @dt-ui/react-icon@0.1.0-beta.12
334
+
335
+ ## 0.1.0-beta.6
336
+
337
+ ### Patch Changes
338
+
339
+ - fix: update border radius theme specifications
340
+ - Updated dependencies
341
+ - @dt-ui/react-core@0.1.0-beta.14
342
+ - @dt-ui/react-icon@0.1.0-beta.11
343
+
344
+ ## 0.1.0-beta.5
345
+
346
+ ### Minor Changes
347
+
348
+ - feat: add onClick on Icon
349
+
350
+ ### Patch Changes
351
+
352
+ - Updated dependencies
353
+ - @dt-ui/react-icon@0.1.0-beta.10
354
+
355
+ ## 0.1.0-beta.4
356
+
357
+ ### Patch Changes
358
+
359
+ - fix: match accordion design
360
+ - Updated dependencies
361
+ - @dt-ui/react-core@0.1.0-beta.13
362
+ - @dt-ui/react-icon@0.1.0-beta.9
363
+
364
+ ## 0.1.0-beta.3
365
+
366
+ ### Patch Changes
367
+
368
+ - fix: make icons an optional property in theme
369
+ - Updated dependencies
370
+ - @dt-ui/react-core@0.1.0-beta.12
371
+ - @dt-ui/react-icon@0.1.0-beta.8
372
+
373
+ ## 0.1.0-beta.2
374
+
375
+ ### Patch Changes
376
+
377
+ - refactor: extract text-field to new package with greenlane theme
378
+ - Updated dependencies
379
+ - @dt-ui/react-core@0.1.0-beta.11
380
+ - @dt-ui/react-icon@0.1.0-beta.7
381
+
382
+ ## 0.1.0-beta.1
383
+
384
+ ### Patch Changes
385
+
386
+ - refactor: move and refactor checkbox refactor checkbox according to design
387
+ - Updated dependencies
388
+ - @dt-ui/react-core@0.1.0-beta.10
389
+ - @dt-ui/react-icon@0.1.0-beta.6
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,82 @@
1
+ # Checkbox Package
2
+
3
+ A checkbox toggles between checked and unchecked states, enabling users to make binary choices in forms and settings.
4
+
5
+ ## Checkbox Usage
6
+
7
+ ```jsx
8
+ import { Checkbox } from '@dt-dds/react-checkbox';
9
+
10
+ export const App = () => {
11
+ const [checked, setChecked] = React.useState(true);
12
+
13
+ const handleChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
14
+ setChecked(evt.target.checked);
15
+ };
16
+
17
+ return (
18
+ <Checkbox isChecked={checked} onChange={handleChange}>
19
+ Label
20
+ </Checkbox>
21
+ );
22
+ };
23
+ ```
24
+
25
+ ## Properties
26
+
27
+ | Property | Type | Default | Description |
28
+ | ------------ | ---------------------------------------------- | ------------- | ----------------------------------------------------------------------------- |
29
+ | `children` | `ReactNode` | - | Child components to be rendered as the label. |
30
+ | `onChange` | `(evt: ChangeEvent<HTMLInputElement>) => void` | - | The triggered function when the input change. |
31
+ | `isDisabled` | `boolean` | `false` | Specifies if the element should be disabled. |
32
+ | `isChecked` | `boolean` | `false` | Specifies if the element should be pre-selected (checked) when the page loads |
33
+ | `dataTestId` | `string` | `checkbox-id` | Customizable test identifier |
34
+
35
+ ### Note
36
+
37
+ In addition to the above properties, this component also accepts all standard props of an `input` element.
38
+
39
+ ## Stack
40
+
41
+ - [TypeScript](https://www.typescriptlang.org/) for static type checking
42
+ - [React](https://reactjs.org/) — JavaScript library for user interfaces
43
+ - [Emotion](https://emotion.sh/docs/introduction) — for writing css styles with JavaScript
44
+ - [Storybook](https://storybook.js.org/) — UI component environment powered by Vite
45
+ - [Jest](https://jestjs.io/) - JavaScript Testing Framework
46
+ - [React Testing Library](https://testing-library.com/) - to test UI components in a user-centric way
47
+ - [ESLint](https://eslint.org/) for code linting
48
+ - [Prettier](https://prettier.io) for code formatting
49
+ - [Tsup](https://github.com/egoist/tsup) — TypeScript bundler powered by esbuild
50
+ - [Yarn](https://yarnpkg.com/) from managing packages
51
+
52
+ ## Commands
53
+
54
+ - `yarn build` - Build the package
55
+ - `yarn dev` - Run the package locally
56
+ - `yarn lint` - Lint all files within this package
57
+ - `yarn test` Run all unit tests
58
+ - `yarn test:report` - Open the test coverage report
59
+ - `yarn test:update:snapshot` - Run all unit tests and update the snapshot
60
+
61
+ ## Compilation
62
+
63
+ 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.
64
+
65
+ The `/dist` folder contains the compiled output.
66
+
67
+ ```bash
68
+ checkbox
69
+ └── dist
70
+ ├── index.d.ts <-- Types
71
+ ├── index.js <-- CommonJS version
72
+ └── index.mjs <-- ES Modules version
73
+ ...
74
+ ```
75
+
76
+ ## Versioning
77
+
78
+ Follows [semantic versioning](https://semver.org/)
79
+
80
+ ## &copy; License
81
+
82
+ Licensed under [MIT License](LICENSE.md)
@@ -0,0 +1,17 @@
1
+ import { BaseProps, Theme } from '@dt-dds/react-core';
2
+ import * as react from 'react';
3
+ import { ComponentPropsWithRef, ChangeEvent } from 'react';
4
+
5
+ interface CheckBoxProps extends BaseProps, ComponentPropsWithRef<'input'> {
6
+ onChange?: (evt: ChangeEvent<HTMLInputElement>) => void;
7
+ isChecked?: boolean;
8
+ isDisabled?: boolean;
9
+ }
10
+ declare const Checkbox: react.ForwardRefExoticComponent<Omit<CheckBoxProps, "ref"> & react.RefAttributes<HTMLInputElement>>;
11
+
12
+ declare module '@emotion/react' {
13
+ interface Theme extends Theme {
14
+ }
15
+ }
16
+
17
+ export { CheckBoxProps, Checkbox };
package/dist/index.js ADDED
@@ -0,0 +1,199 @@
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 __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __objRest = (source, exclude) => {
23
+ var target = {};
24
+ for (var prop in source)
25
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
26
+ target[prop] = source[prop];
27
+ if (source != null && __getOwnPropSymbols)
28
+ for (var prop of __getOwnPropSymbols(source)) {
29
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
30
+ target[prop] = source[prop];
31
+ }
32
+ return target;
33
+ };
34
+ var __export = (target, all) => {
35
+ for (var name in all)
36
+ __defProp(target, name, { get: all[name], enumerable: true });
37
+ };
38
+ var __copyProps = (to, from, except, desc) => {
39
+ if (from && typeof from === "object" || typeof from === "function") {
40
+ for (let key of __getOwnPropNames(from))
41
+ if (!__hasOwnProp.call(to, key) && key !== except)
42
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
43
+ }
44
+ return to;
45
+ };
46
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
47
+ // If the importer is in node compatibility mode or this is not an ESM
48
+ // file that has been converted to a CommonJS file using a Babel-
49
+ // compatible transform (i.e. "__esModule" has not been set), then set
50
+ // "default" to the CommonJS "module.exports" for node compatibility.
51
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
52
+ mod
53
+ ));
54
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
55
+
56
+ // index.ts
57
+ var checkbox_exports = {};
58
+ __export(checkbox_exports, {
59
+ Checkbox: () => Checkbox
60
+ });
61
+ module.exports = __toCommonJS(checkbox_exports);
62
+
63
+ // src/Checkbox.tsx
64
+ var import_react_icon = require("@dt-dds/react-icon");
65
+ var import_react = require("@emotion/react");
66
+ var import_react2 = require("react");
67
+
68
+ // src/Checkbox.styled.ts
69
+ var import_styled = __toESM(require("@emotion/styled"));
70
+
71
+ // src/utils/checkboxStyles.ts
72
+ var checkboxStyles = (theme, isChecked, isDisabled) => {
73
+ if (isChecked) {
74
+ return `
75
+ border: none;
76
+ background-color: ${isDisabled ? theme.palette.primary.light : theme.palette.accent.default};
77
+ `;
78
+ }
79
+ return `
80
+ border: 1px solid ${theme.palette.border.default};
81
+ background-color: ${theme.palette.surface.contrast};
82
+ `;
83
+ };
84
+
85
+ // src/Checkbox.styled.ts
86
+ var CheckboxStyled = import_styled.default.label`
87
+ display: flex;
88
+ align-items: center;
89
+ width: 100%;
90
+
91
+ ${({ theme, isChecked, isDisabled }) => `
92
+ & > div {
93
+ border-radius: ${theme.shape.checkbox};
94
+ ${checkboxStyles(theme, isChecked, isDisabled)}
95
+ }
96
+ cursor: ${isDisabled ? "not-allowed" : "pointer"};
97
+
98
+ &:hover > div {
99
+ ${!isDisabled && !isChecked && `
100
+ background-color: ${theme.palette.primary.light};
101
+ border: 1px solid ${theme.palette.primary.default};
102
+ `};
103
+ }
104
+ `}
105
+ `;
106
+ var CheckBoxInputWrapper = import_styled.default.div`
107
+ height: 24px;
108
+ min-height: 24px;
109
+ width: 24px;
110
+ min-width: 24px;
111
+ position: relative;
112
+ display: flex;
113
+ `;
114
+ var CheckboxInputStyled = import_styled.default.input`
115
+ cursor: pointer;
116
+ appearance: none;
117
+ position: absolute;
118
+ width: 100%;
119
+ height: 100%;
120
+ top: 0;
121
+ left: 0;
122
+ margin: 0;
123
+ padding: 0;
124
+
125
+ &:disabled {
126
+ cursor: not-allowed;
127
+ }
128
+ `;
129
+ var CheckboxLabelStyled = import_styled.default.span`
130
+ user-select: none;
131
+ text-overflow: ellipsis;
132
+ white-space: nowrap;
133
+ overflow: hidden;
134
+ width: 100%;
135
+
136
+ ${({ theme, isDisabled }) => `
137
+ padding-left: ${theme.spacing["4xs"]};
138
+ ${theme.fontStyles.body2};
139
+ color: ${isDisabled ? theme.palette.content.light : theme.palette.content.default};
140
+ `}
141
+ `;
142
+
143
+ // src/Checkbox.tsx
144
+ var import_jsx_runtime = require("react/jsx-runtime");
145
+ var Checkbox = (0, import_react2.forwardRef)(
146
+ (_a, ref) => {
147
+ var _b = _a, {
148
+ dataTestId = "checkbox-id",
149
+ onChange,
150
+ children,
151
+ isChecked = false,
152
+ isDisabled = false,
153
+ style
154
+ } = _b, rest = __objRest(_b, [
155
+ "dataTestId",
156
+ "onChange",
157
+ "children",
158
+ "isChecked",
159
+ "isDisabled",
160
+ "style"
161
+ ]);
162
+ const theme = (0, import_react.useTheme)();
163
+ const handleOnChangeTrigger = (event) => {
164
+ if (isDisabled) {
165
+ return;
166
+ }
167
+ onChange == null ? void 0 : onChange(event);
168
+ };
169
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
170
+ CheckboxStyled,
171
+ {
172
+ "data-testid": dataTestId,
173
+ isChecked,
174
+ isDisabled,
175
+ style,
176
+ children: [
177
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(CheckBoxInputWrapper, { children: [
178
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
179
+ CheckboxInputStyled,
180
+ __spreadValues({
181
+ checked: isChecked,
182
+ disabled: isDisabled,
183
+ onChange: handleOnChangeTrigger,
184
+ ref,
185
+ type: "checkbox"
186
+ }, rest)
187
+ ),
188
+ isChecked ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icon.Icon, { code: "check", color: theme.palette.content.contrast }) : null
189
+ ] }),
190
+ children ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxLabelStyled, { isChecked, isDisabled, children }) : null
191
+ ]
192
+ }
193
+ );
194
+ }
195
+ );
196
+ // Annotate the CommonJS export names for ESM import in node:
197
+ 0 && (module.exports = {
198
+ Checkbox
199
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,165 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __objRest = (source, exclude) => {
18
+ var target = {};
19
+ for (var prop in source)
20
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
+ target[prop] = source[prop];
22
+ if (source != null && __getOwnPropSymbols)
23
+ for (var prop of __getOwnPropSymbols(source)) {
24
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
+ target[prop] = source[prop];
26
+ }
27
+ return target;
28
+ };
29
+
30
+ // src/Checkbox.tsx
31
+ import { Icon } from "@dt-dds/react-icon";
32
+ import { useTheme } from "@emotion/react";
33
+ import { forwardRef } from "react";
34
+
35
+ // src/Checkbox.styled.ts
36
+ import styled from "@emotion/styled";
37
+
38
+ // src/utils/checkboxStyles.ts
39
+ var checkboxStyles = (theme, isChecked, isDisabled) => {
40
+ if (isChecked) {
41
+ return `
42
+ border: none;
43
+ background-color: ${isDisabled ? theme.palette.primary.light : theme.palette.accent.default};
44
+ `;
45
+ }
46
+ return `
47
+ border: 1px solid ${theme.palette.border.default};
48
+ background-color: ${theme.palette.surface.contrast};
49
+ `;
50
+ };
51
+
52
+ // src/Checkbox.styled.ts
53
+ var CheckboxStyled = styled.label`
54
+ display: flex;
55
+ align-items: center;
56
+ width: 100%;
57
+
58
+ ${({ theme, isChecked, isDisabled }) => `
59
+ & > div {
60
+ border-radius: ${theme.shape.checkbox};
61
+ ${checkboxStyles(theme, isChecked, isDisabled)}
62
+ }
63
+ cursor: ${isDisabled ? "not-allowed" : "pointer"};
64
+
65
+ &:hover > div {
66
+ ${!isDisabled && !isChecked && `
67
+ background-color: ${theme.palette.primary.light};
68
+ border: 1px solid ${theme.palette.primary.default};
69
+ `};
70
+ }
71
+ `}
72
+ `;
73
+ var CheckBoxInputWrapper = styled.div`
74
+ height: 24px;
75
+ min-height: 24px;
76
+ width: 24px;
77
+ min-width: 24px;
78
+ position: relative;
79
+ display: flex;
80
+ `;
81
+ var CheckboxInputStyled = styled.input`
82
+ cursor: pointer;
83
+ appearance: none;
84
+ position: absolute;
85
+ width: 100%;
86
+ height: 100%;
87
+ top: 0;
88
+ left: 0;
89
+ margin: 0;
90
+ padding: 0;
91
+
92
+ &:disabled {
93
+ cursor: not-allowed;
94
+ }
95
+ `;
96
+ var CheckboxLabelStyled = styled.span`
97
+ user-select: none;
98
+ text-overflow: ellipsis;
99
+ white-space: nowrap;
100
+ overflow: hidden;
101
+ width: 100%;
102
+
103
+ ${({ theme, isDisabled }) => `
104
+ padding-left: ${theme.spacing["4xs"]};
105
+ ${theme.fontStyles.body2};
106
+ color: ${isDisabled ? theme.palette.content.light : theme.palette.content.default};
107
+ `}
108
+ `;
109
+
110
+ // src/Checkbox.tsx
111
+ import { jsx, jsxs } from "react/jsx-runtime";
112
+ var Checkbox = forwardRef(
113
+ (_a, ref) => {
114
+ var _b = _a, {
115
+ dataTestId = "checkbox-id",
116
+ onChange,
117
+ children,
118
+ isChecked = false,
119
+ isDisabled = false,
120
+ style
121
+ } = _b, rest = __objRest(_b, [
122
+ "dataTestId",
123
+ "onChange",
124
+ "children",
125
+ "isChecked",
126
+ "isDisabled",
127
+ "style"
128
+ ]);
129
+ const theme = useTheme();
130
+ const handleOnChangeTrigger = (event) => {
131
+ if (isDisabled) {
132
+ return;
133
+ }
134
+ onChange == null ? void 0 : onChange(event);
135
+ };
136
+ return /* @__PURE__ */ jsxs(
137
+ CheckboxStyled,
138
+ {
139
+ "data-testid": dataTestId,
140
+ isChecked,
141
+ isDisabled,
142
+ style,
143
+ children: [
144
+ /* @__PURE__ */ jsxs(CheckBoxInputWrapper, { children: [
145
+ /* @__PURE__ */ jsx(
146
+ CheckboxInputStyled,
147
+ __spreadValues({
148
+ checked: isChecked,
149
+ disabled: isDisabled,
150
+ onChange: handleOnChangeTrigger,
151
+ ref,
152
+ type: "checkbox"
153
+ }, rest)
154
+ ),
155
+ isChecked ? /* @__PURE__ */ jsx(Icon, { code: "check", color: theme.palette.content.contrast }) : null
156
+ ] }),
157
+ children ? /* @__PURE__ */ jsx(CheckboxLabelStyled, { isChecked, isDisabled, children }) : null
158
+ ]
159
+ }
160
+ );
161
+ }
162
+ );
163
+ export {
164
+ Checkbox
165
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@dt-dds/react-checkbox",
3
+ "version": "1.0.0-beta.40",
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-icon": "1.0.0-beta.42"
25
+ },
26
+ "devDependencies": {
27
+ "@babel/core": "^7.22.9",
28
+ "@babel/preset-env": "^7.22.9",
29
+ "@babel/preset-react": "^7.22.5",
30
+ "@babel/preset-typescript": "^7.23.3",
31
+ "@emotion/babel-plugin": "^11.11.0",
32
+ "@emotion/css": "^11.7.1",
33
+ "@emotion/jest": "^11.10.0",
34
+ "@emotion/react": "^11.8.2",
35
+ "@emotion/styled": "^11.8.1",
36
+ "@types/react": "^18.0.9",
37
+ "@types/react-dom": "^18.0.4",
38
+ "babel-loader": "^8.3.0",
39
+ "eslint-config-custom": "*",
40
+ "eslint-plugin-storybook": "^9.1.0",
41
+ "jest-config": "*",
42
+ "react": "^18.1.0",
43
+ "react-dom": "^18.2.0",
44
+ "tsconfig": "*",
45
+ "tsup": "^6.6.3",
46
+ "typescript": "^4.5.3"
47
+ },
48
+ "peerDependencies": {
49
+ "@emotion/css": "^11.7.1",
50
+ "@emotion/react": "^11.8.2",
51
+ "@emotion/styled": "^11.8.1",
52
+ "react": ">=17.0.2",
53
+ "react-dom": ">=17.0.2"
54
+ }
55
+ }