@dt-dds/react-radio 1.0.0-beta.25
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 +228 -0
- package/LICENSE.md +21 -0
- package/README.md +86 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +172 -0
- package/dist/index.mjs +137 -0
- package/package.json +55 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# @dt-ui/react-radio
|
|
2
|
+
|
|
3
|
+
## 1.0.0-beta.25
|
|
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-box@1.0.0-beta.9
|
|
13
|
+
- @dt-dds/react-core@1.0.0-beta.41
|
|
14
|
+
|
|
15
|
+
## 0.1.0-beta.24
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- refactor: theme typography values
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
- @dt-ui/react-core@0.1.0-beta.40
|
|
22
|
+
|
|
23
|
+
## 0.1.0-beta.23
|
|
24
|
+
|
|
25
|
+
### Minor Changes
|
|
26
|
+
|
|
27
|
+
- feat: update shadow theme values
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies
|
|
32
|
+
- @dt-ui/react-core@0.1.0-beta.39
|
|
33
|
+
|
|
34
|
+
## 0.1.0-beta.22
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- chore: update theme font-styles
|
|
39
|
+
- Updated dependencies
|
|
40
|
+
- @dt-ui/react-core@0.1.0-beta.38
|
|
41
|
+
|
|
42
|
+
## 0.1.0-beta.21
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- chore: review OSS files
|
|
47
|
+
- Updated dependencies
|
|
48
|
+
- @dt-ui/react-box@0.1.0-beta.8
|
|
49
|
+
- @dt-ui/react-core@0.1.0-beta.37
|
|
50
|
+
|
|
51
|
+
## 0.1.0-beta.20
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- chore: update contextual colors
|
|
56
|
+
- Updated dependencies
|
|
57
|
+
- @dt-ui/react-core@0.1.0-beta.36
|
|
58
|
+
|
|
59
|
+
## 0.1.0-beta.19
|
|
60
|
+
|
|
61
|
+
### Patch Changes
|
|
62
|
+
|
|
63
|
+
- fix: change content.light contextual color
|
|
64
|
+
- Updated dependencies
|
|
65
|
+
- @dt-ui/react-core@0.1.0-beta.35
|
|
66
|
+
|
|
67
|
+
## 0.1.0-beta.18
|
|
68
|
+
|
|
69
|
+
### Patch Changes
|
|
70
|
+
|
|
71
|
+
- fix: add accent to colors type
|
|
72
|
+
- Updated dependencies
|
|
73
|
+
- @dt-ui/react-core@0.1.0-beta.34
|
|
74
|
+
|
|
75
|
+
## 0.1.0-beta.17
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- fix: change button text according to ux
|
|
80
|
+
- Updated dependencies
|
|
81
|
+
- @dt-ui/react-core@0.1.0-beta.33
|
|
82
|
+
|
|
83
|
+
## 0.1.0-beta.16
|
|
84
|
+
|
|
85
|
+
### Patch Changes
|
|
86
|
+
|
|
87
|
+
- chore: update contexual colors
|
|
88
|
+
- Updated dependencies
|
|
89
|
+
- @dt-ui/react-core@0.1.0-beta.32
|
|
90
|
+
|
|
91
|
+
## 0.1.0-beta.15
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- style: update responsive font styles
|
|
96
|
+
- Updated dependencies
|
|
97
|
+
- @dt-ui/react-core@0.1.0-beta.31
|
|
98
|
+
|
|
99
|
+
## 0.1.0-beta.14
|
|
100
|
+
|
|
101
|
+
### Minor Changes
|
|
102
|
+
|
|
103
|
+
- feat: add spinner size 'extra-small' & update specs
|
|
104
|
+
|
|
105
|
+
### Patch Changes
|
|
106
|
+
|
|
107
|
+
- Updated dependencies
|
|
108
|
+
- @dt-ui/react-core@0.1.0-beta.30
|
|
109
|
+
|
|
110
|
+
## 0.1.0-beta.13
|
|
111
|
+
|
|
112
|
+
### Patch Changes
|
|
113
|
+
|
|
114
|
+
- chore: add theme breakpoints
|
|
115
|
+
- Updated dependencies
|
|
116
|
+
- @dt-ui/react-core@0.1.0-beta.29
|
|
117
|
+
|
|
118
|
+
## 0.1.0-beta.12
|
|
119
|
+
|
|
120
|
+
### Minor Changes
|
|
121
|
+
|
|
122
|
+
- feat: add id to base props
|
|
123
|
+
|
|
124
|
+
### Patch Changes
|
|
125
|
+
|
|
126
|
+
- Updated dependencies
|
|
127
|
+
- @dt-ui/react-core@0.1.0-beta.28
|
|
128
|
+
|
|
129
|
+
## 0.1.0-beta.11
|
|
130
|
+
|
|
131
|
+
### Minor Changes
|
|
132
|
+
|
|
133
|
+
- feat: change breakpoints values
|
|
134
|
+
|
|
135
|
+
### Patch Changes
|
|
136
|
+
|
|
137
|
+
- Updated dependencies
|
|
138
|
+
- @dt-ui/react-core@0.1.0-beta.27
|
|
139
|
+
|
|
140
|
+
## 0.1.0-beta.10
|
|
141
|
+
|
|
142
|
+
### Patch Changes
|
|
143
|
+
|
|
144
|
+
- fix: replace body to correct one
|
|
145
|
+
- Updated dependencies
|
|
146
|
+
- @dt-ui/react-core@0.1.0-beta.26
|
|
147
|
+
|
|
148
|
+
## 0.1.0-beta.9
|
|
149
|
+
|
|
150
|
+
### Patch Changes
|
|
151
|
+
|
|
152
|
+
- chore: add theme colors missing types
|
|
153
|
+
- Updated dependencies
|
|
154
|
+
- @dt-ui/react-core@0.1.0-beta.25
|
|
155
|
+
|
|
156
|
+
## 0.1.0-beta.8
|
|
157
|
+
|
|
158
|
+
### Patch Changes
|
|
159
|
+
|
|
160
|
+
- refactor: drop truckapi theme
|
|
161
|
+
- Updated dependencies
|
|
162
|
+
- @dt-ui/react-core@0.1.0-beta.24
|
|
163
|
+
|
|
164
|
+
## 0.1.0-beta.7
|
|
165
|
+
|
|
166
|
+
### Minor Changes
|
|
167
|
+
|
|
168
|
+
- feat: update core and semantic colors
|
|
169
|
+
- feat: remove greenlane theme
|
|
170
|
+
|
|
171
|
+
### Patch Changes
|
|
172
|
+
|
|
173
|
+
- Updated dependencies
|
|
174
|
+
- Updated dependencies
|
|
175
|
+
- @dt-ui/react-core@0.1.0-beta.23
|
|
176
|
+
|
|
177
|
+
## 0.1.0-beta.6
|
|
178
|
+
|
|
179
|
+
### Minor Changes
|
|
180
|
+
|
|
181
|
+
- feat: add icon option for truckapi theme
|
|
182
|
+
|
|
183
|
+
### Patch Changes
|
|
184
|
+
|
|
185
|
+
- Updated dependencies
|
|
186
|
+
- @dt-ui/react-core@0.1.0-beta.22
|
|
187
|
+
|
|
188
|
+
## 0.1.0-beta.5
|
|
189
|
+
|
|
190
|
+
### Patch Changes
|
|
191
|
+
|
|
192
|
+
- fix: tooltip z index
|
|
193
|
+
- Updated dependencies
|
|
194
|
+
- @dt-ui/react-core@0.1.0-beta.21
|
|
195
|
+
|
|
196
|
+
## 0.1.0-beta.4
|
|
197
|
+
|
|
198
|
+
### Minor Changes
|
|
199
|
+
|
|
200
|
+
- feat: add segmented control component
|
|
201
|
+
|
|
202
|
+
### Patch Changes
|
|
203
|
+
|
|
204
|
+
- Updated dependencies
|
|
205
|
+
- @dt-ui/react-core@0.1.0-beta.20
|
|
206
|
+
|
|
207
|
+
## 0.1.0-beta.3
|
|
208
|
+
|
|
209
|
+
### Patch Changes
|
|
210
|
+
|
|
211
|
+
- fix: add shape for tooltip on truckapi theme
|
|
212
|
+
- Updated dependencies
|
|
213
|
+
- @dt-ui/react-core@0.1.0-beta.19
|
|
214
|
+
|
|
215
|
+
## 0.1.0-beta.2
|
|
216
|
+
|
|
217
|
+
### Patch Changes
|
|
218
|
+
|
|
219
|
+
- test: change back to using withProviders
|
|
220
|
+
- fix: remove devDependecy export
|
|
221
|
+
- Updated dependencies
|
|
222
|
+
- @dt-ui/react-core@0.1.0-beta.18
|
|
223
|
+
|
|
224
|
+
## 0.1.0-beta.1
|
|
225
|
+
|
|
226
|
+
### Patch Changes
|
|
227
|
+
|
|
228
|
+
- chore: make radio independent pkg
|
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,86 @@
|
|
|
1
|
+
# Radio Package
|
|
2
|
+
|
|
3
|
+
The Radio package allows to select one option from a set.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```jsx
|
|
8
|
+
import { Radio, RadioGroup } from '@dt-dds/react';
|
|
9
|
+
|
|
10
|
+
export const App = () => {
|
|
11
|
+
return (
|
|
12
|
+
<RadioGroup onChange={onChange} name='group-name'>
|
|
13
|
+
<Radio value='1' label='Label 1' isDefaultChecked={true} />
|
|
14
|
+
<Radio value='2' label='Label 2' isDisabled={true} />
|
|
15
|
+
</RadioGroup>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Properties
|
|
21
|
+
|
|
22
|
+
### Radio
|
|
23
|
+
|
|
24
|
+
| Property | Type | Default | Description |
|
|
25
|
+
| ------------------ | ---------------------------------------------- | ------------------ | ------------------------------------------------------------------------------------- |
|
|
26
|
+
| `label` | `string` | - | A label to help users understand the scope of the radio. |
|
|
27
|
+
| `onChange` | `(evt: ChangeEvent<HTMLInputElement>) => void` | - | The triggered function when the input change. |
|
|
28
|
+
| `isDisabled` | `boolean` | `false` | Specifies if the element should be disabled. |
|
|
29
|
+
| `isDefaultChecked` | `boolean` | `false` | If present, indicates that this radio button is the default selected one in the group |
|
|
30
|
+
| `name` | `string` | 'radio-group-name' | Should represent the group name |
|
|
31
|
+
| `value` | `string` | - | String containing the radio button's value |
|
|
32
|
+
|
|
33
|
+
### RadioGroup
|
|
34
|
+
|
|
35
|
+
| Property | Type | Default | Description |
|
|
36
|
+
| ------------ | ---------------------------------------------- | ------- | --------------------------------------------- |
|
|
37
|
+
| `children` | `ReactNode` | - | Child components to be rendered |
|
|
38
|
+
| `dataTestId` | `string` | - | Customizable test identifier |
|
|
39
|
+
| `direction` | "row" \| "column" | row | Sets the flex direction of the group |
|
|
40
|
+
| `name` | `string` | - | Should represent the group name |
|
|
41
|
+
| `onChange` | `(evt: ChangeEvent<HTMLInputElement>) => void` | - | The triggered function when the input change. |
|
|
42
|
+
|
|
43
|
+
## Stack
|
|
44
|
+
|
|
45
|
+
- [TypeScript](https://www.typescriptlang.org/) for static type checking
|
|
46
|
+
- [React](https://reactjs.org/) — JavaScript library for user interfaces
|
|
47
|
+
- [Emotion](https://emotion.sh/docs/introduction) — for writing css styles with JavaScript
|
|
48
|
+
- [Storybook](https://storybook.js.org/) — UI component environment powered by Vite
|
|
49
|
+
- [Jest](https://jestjs.io/) - JavaScript Testing Framework
|
|
50
|
+
- [React Testing Library](https://testing-library.com/) - to test UI components in a user-centric way
|
|
51
|
+
- [ESLint](https://eslint.org/) for code linting
|
|
52
|
+
- [Prettier](https://prettier.io) for code formatting
|
|
53
|
+
- [Tsup](https://github.com/egoist/tsup) — TypeScript bundler powered by esbuild
|
|
54
|
+
- [Yarn](https://yarnpkg.com/) from managing packages
|
|
55
|
+
|
|
56
|
+
## Commands
|
|
57
|
+
|
|
58
|
+
- `yarn build` - Build the package
|
|
59
|
+
- `yarn dev` - Run the package locally
|
|
60
|
+
- `yarn lint` - Lint all files within this package
|
|
61
|
+
- `yarn test` - Run all unit tests
|
|
62
|
+
- `yarn test:report` - Open the test coverage report
|
|
63
|
+
- `yarn test:update:snapshot` - Run all unit tests and update the snapshot
|
|
64
|
+
|
|
65
|
+
## Compilation
|
|
66
|
+
|
|
67
|
+
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.
|
|
68
|
+
|
|
69
|
+
The `/dist` folder contains the compiled output.
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
radio
|
|
73
|
+
└── dist
|
|
74
|
+
├── index.d.ts <-- Types
|
|
75
|
+
├── index.js <-- CommonJS version
|
|
76
|
+
└── index.mjs <-- ES Modules version
|
|
77
|
+
...
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Versioning
|
|
81
|
+
|
|
82
|
+
Follows [semantic versioning](https://semver.org/)
|
|
83
|
+
|
|
84
|
+
## © License
|
|
85
|
+
|
|
86
|
+
Licensed under [MIT License](LICENSE.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BaseProps, Theme } from '@dt-dds/react-core';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
type Direction = 'column' | 'row';
|
|
5
|
+
interface RadioGroupProps extends BaseProps {
|
|
6
|
+
onChange: React.ChangeEventHandler<HTMLInputElement>;
|
|
7
|
+
name: string;
|
|
8
|
+
direction?: Direction;
|
|
9
|
+
}
|
|
10
|
+
interface RadioProps {
|
|
11
|
+
label: string;
|
|
12
|
+
value: string;
|
|
13
|
+
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
14
|
+
isDefaultChecked?: boolean;
|
|
15
|
+
isDisabled?: boolean;
|
|
16
|
+
name?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare const RadioGroup: ({ children, onChange, dataTestId, direction, name, }: RadioGroupProps) => react_jsx_runtime.JSX.Element;
|
|
20
|
+
declare const Radio: ({ onChange, label, isDefaultChecked, isDisabled, name, value, }: RadioProps) => react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
declare module '@emotion/react' {
|
|
23
|
+
interface Theme extends Theme {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { Radio, RadioGroup };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
for (var name in all)
|
|
27
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
+
};
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from))
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
+
mod
|
|
44
|
+
));
|
|
45
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
+
|
|
47
|
+
// index.ts
|
|
48
|
+
var radio_exports = {};
|
|
49
|
+
__export(radio_exports, {
|
|
50
|
+
Radio: () => Radio_default,
|
|
51
|
+
RadioGroup: () => RadioGroup
|
|
52
|
+
});
|
|
53
|
+
module.exports = __toCommonJS(radio_exports);
|
|
54
|
+
|
|
55
|
+
// src/Radio.tsx
|
|
56
|
+
var import_react_box = require("@dt-dds/react-box");
|
|
57
|
+
var import_react = require("react");
|
|
58
|
+
|
|
59
|
+
// src/Radio.styled.tsx
|
|
60
|
+
var import_styled = __toESM(require("@emotion/styled"));
|
|
61
|
+
var RadioInputStyled = import_styled.default.input`
|
|
62
|
+
${({ theme }) => `
|
|
63
|
+
background: ${theme.palette.surface.contrast};
|
|
64
|
+
border: 1px solid ${theme.palette.border.default};
|
|
65
|
+
border-radius: 50%;
|
|
66
|
+
width: 24px;
|
|
67
|
+
height: 24px;
|
|
68
|
+
appearance: none;
|
|
69
|
+
|
|
70
|
+
&:disabled {
|
|
71
|
+
pointer-events: none;
|
|
72
|
+
cursor: not-allowed;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&:disabled + label {
|
|
76
|
+
color: ${theme.palette.content.light};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&:checked {
|
|
80
|
+
border-width: 7px;
|
|
81
|
+
border-color: ${theme.palette.primary.default};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
&:checked:disabled {
|
|
85
|
+
border-color: ${theme.palette.primary.medium};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&:checked:before {
|
|
89
|
+
content: '';
|
|
90
|
+
height: 10px;
|
|
91
|
+
width: 10px;
|
|
92
|
+
border-radius: 50%;
|
|
93
|
+
display: block;
|
|
94
|
+
}
|
|
95
|
+
`}
|
|
96
|
+
`;
|
|
97
|
+
var RadioLabelStyled = import_styled.default.label`
|
|
98
|
+
${({ theme }) => `
|
|
99
|
+
${theme.fontStyles.p};
|
|
100
|
+
color: ${theme.palette.content.default};
|
|
101
|
+
cursor: inherit;
|
|
102
|
+
`}
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
// src/Radio.tsx
|
|
106
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
107
|
+
var RadioGroup = ({
|
|
108
|
+
children,
|
|
109
|
+
onChange,
|
|
110
|
+
dataTestId,
|
|
111
|
+
direction = "row",
|
|
112
|
+
name
|
|
113
|
+
}) => {
|
|
114
|
+
const clonedChildren = (0, import_react.useMemo)(
|
|
115
|
+
() => import_react.Children.map(children, (child) => {
|
|
116
|
+
return child && (0, import_react.cloneElement)(child, __spreadProps(__spreadValues({}, child.props), {
|
|
117
|
+
onChange,
|
|
118
|
+
name
|
|
119
|
+
}));
|
|
120
|
+
}),
|
|
121
|
+
[children, onChange, name]
|
|
122
|
+
);
|
|
123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
|
+
import_react_box.Box,
|
|
125
|
+
{
|
|
126
|
+
"data-testid": dataTestId != null ? dataTestId : "radio-group",
|
|
127
|
+
style: { flexDirection: direction, gap: 12 },
|
|
128
|
+
children: clonedChildren
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
var Radio = ({
|
|
133
|
+
onChange,
|
|
134
|
+
label,
|
|
135
|
+
isDefaultChecked,
|
|
136
|
+
isDisabled,
|
|
137
|
+
name = "radio-group-name",
|
|
138
|
+
value
|
|
139
|
+
}) => {
|
|
140
|
+
const radioId = `${value}-id`;
|
|
141
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
142
|
+
import_react_box.Box,
|
|
143
|
+
{
|
|
144
|
+
style: {
|
|
145
|
+
flexDirection: "row",
|
|
146
|
+
gap: 8,
|
|
147
|
+
cursor: isDisabled ? "not-allowed" : "pointer"
|
|
148
|
+
},
|
|
149
|
+
children: [
|
|
150
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
151
|
+
RadioInputStyled,
|
|
152
|
+
{
|
|
153
|
+
defaultChecked: isDefaultChecked,
|
|
154
|
+
disabled: isDisabled,
|
|
155
|
+
id: radioId,
|
|
156
|
+
name,
|
|
157
|
+
onChange,
|
|
158
|
+
type: "radio",
|
|
159
|
+
value
|
|
160
|
+
}
|
|
161
|
+
),
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadioLabelStyled, { htmlFor: radioId, children: label })
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
var Radio_default = Radio;
|
|
168
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
169
|
+
0 && (module.exports = {
|
|
170
|
+
Radio,
|
|
171
|
+
RadioGroup
|
|
172
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
|
|
21
|
+
// src/Radio.tsx
|
|
22
|
+
import { Box } from "@dt-dds/react-box";
|
|
23
|
+
import { Children, cloneElement, useMemo } from "react";
|
|
24
|
+
|
|
25
|
+
// src/Radio.styled.tsx
|
|
26
|
+
import styled from "@emotion/styled";
|
|
27
|
+
var RadioInputStyled = styled.input`
|
|
28
|
+
${({ theme }) => `
|
|
29
|
+
background: ${theme.palette.surface.contrast};
|
|
30
|
+
border: 1px solid ${theme.palette.border.default};
|
|
31
|
+
border-radius: 50%;
|
|
32
|
+
width: 24px;
|
|
33
|
+
height: 24px;
|
|
34
|
+
appearance: none;
|
|
35
|
+
|
|
36
|
+
&:disabled {
|
|
37
|
+
pointer-events: none;
|
|
38
|
+
cursor: not-allowed;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&:disabled + label {
|
|
42
|
+
color: ${theme.palette.content.light};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&:checked {
|
|
46
|
+
border-width: 7px;
|
|
47
|
+
border-color: ${theme.palette.primary.default};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
&:checked:disabled {
|
|
51
|
+
border-color: ${theme.palette.primary.medium};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&:checked:before {
|
|
55
|
+
content: '';
|
|
56
|
+
height: 10px;
|
|
57
|
+
width: 10px;
|
|
58
|
+
border-radius: 50%;
|
|
59
|
+
display: block;
|
|
60
|
+
}
|
|
61
|
+
`}
|
|
62
|
+
`;
|
|
63
|
+
var RadioLabelStyled = styled.label`
|
|
64
|
+
${({ theme }) => `
|
|
65
|
+
${theme.fontStyles.p};
|
|
66
|
+
color: ${theme.palette.content.default};
|
|
67
|
+
cursor: inherit;
|
|
68
|
+
`}
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
// src/Radio.tsx
|
|
72
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
73
|
+
var RadioGroup = ({
|
|
74
|
+
children,
|
|
75
|
+
onChange,
|
|
76
|
+
dataTestId,
|
|
77
|
+
direction = "row",
|
|
78
|
+
name
|
|
79
|
+
}) => {
|
|
80
|
+
const clonedChildren = useMemo(
|
|
81
|
+
() => Children.map(children, (child) => {
|
|
82
|
+
return child && cloneElement(child, __spreadProps(__spreadValues({}, child.props), {
|
|
83
|
+
onChange,
|
|
84
|
+
name
|
|
85
|
+
}));
|
|
86
|
+
}),
|
|
87
|
+
[children, onChange, name]
|
|
88
|
+
);
|
|
89
|
+
return /* @__PURE__ */ jsx(
|
|
90
|
+
Box,
|
|
91
|
+
{
|
|
92
|
+
"data-testid": dataTestId != null ? dataTestId : "radio-group",
|
|
93
|
+
style: { flexDirection: direction, gap: 12 },
|
|
94
|
+
children: clonedChildren
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
var Radio = ({
|
|
99
|
+
onChange,
|
|
100
|
+
label,
|
|
101
|
+
isDefaultChecked,
|
|
102
|
+
isDisabled,
|
|
103
|
+
name = "radio-group-name",
|
|
104
|
+
value
|
|
105
|
+
}) => {
|
|
106
|
+
const radioId = `${value}-id`;
|
|
107
|
+
return /* @__PURE__ */ jsxs(
|
|
108
|
+
Box,
|
|
109
|
+
{
|
|
110
|
+
style: {
|
|
111
|
+
flexDirection: "row",
|
|
112
|
+
gap: 8,
|
|
113
|
+
cursor: isDisabled ? "not-allowed" : "pointer"
|
|
114
|
+
},
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ jsx(
|
|
117
|
+
RadioInputStyled,
|
|
118
|
+
{
|
|
119
|
+
defaultChecked: isDefaultChecked,
|
|
120
|
+
disabled: isDisabled,
|
|
121
|
+
id: radioId,
|
|
122
|
+
name,
|
|
123
|
+
onChange,
|
|
124
|
+
type: "radio",
|
|
125
|
+
value
|
|
126
|
+
}
|
|
127
|
+
),
|
|
128
|
+
/* @__PURE__ */ jsx(RadioLabelStyled, { htmlFor: radioId, children: label })
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
var Radio_default = Radio;
|
|
134
|
+
export {
|
|
135
|
+
Radio_default as Radio,
|
|
136
|
+
RadioGroup
|
|
137
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dt-dds/react-radio",
|
|
3
|
+
"version": "1.0.0-beta.25",
|
|
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-box": "1.0.0-beta.9"
|
|
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
|
+
}
|