@cypress-design/react-checkbox 0.1.0 → 0.1.1

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 CHANGED
@@ -1,5 +1,117 @@
1
1
  # @cypress-design/react-checkbox
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#164](https://github.com/cypress-io/cypress-design/pull/164) [`4fd951a`](https://github.com/cypress-io/cypress-design/commit/4fd951a39335900da2508beef9b3565a6f8f9518) Thanks [@elevatebart](https://github.com/elevatebart)! - fix: update active buttons borders
8
+
9
+ ## 0.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#162](https://github.com/cypress-io/cypress-design/pull/162) [`76d4e60`](https://github.com/cypress-io/cypress-design/commit/76d4e601687d28578cdee0ddc67cd04b286ae2c3) Thanks [@elevatebart](https://github.com/elevatebart)! - refactor: functionalize classes used
14
+
15
+ ## 0.5.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#151](https://github.com/cypress-io/cypress-design/pull/151) [`8b0e735`](https://github.com/cypress-io/cypress-design/commit/8b0e7356eb64a6b3583d3486dda8ecbb11c34cca) Thanks [@elevatebart](https://github.com/elevatebart)! - refactor: use clases compatible with both windi and tailwind
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [[`106b61a`](https://github.com/cypress-io/cypress-design/commit/106b61a97888f956a4c9d235fde5efb4243e1445), [`7b4f416`](https://github.com/cypress-io/cypress-design/commit/7b4f4162a0d150aa8cab7ec239faebb58c39464d)]:
24
+ - @cypress-design/react-icon@0.17.0
25
+
26
+ ## 0.4.6
27
+
28
+ ### Patch Changes
29
+
30
+ - [#112](https://github.com/cypress-io/cypress-design/pull/112) [`d229b48`](https://github.com/cypress-io/cypress-design/commit/d229b48a3806a882abe83c9ebf9c32ed18d2c47f) Thanks [@elevatebart](https://github.com/elevatebart)! - fix: when label is too big avoid checkbox shrinking
31
+
32
+ ## 0.4.5
33
+
34
+ ### Patch Changes
35
+
36
+ - [#105](https://github.com/cypress-io/cypress-design/pull/105) [`2f54f5b`](https://github.com/cypress-io/cypress-design/commit/2f54f5b867b60ba5ce2e40fd38870bd65187ba30) Thanks [@elevatebart](https://github.com/elevatebart)! - checkbox should not contain a div to be added inside an inline only tag (<p>)
37
+
38
+ - Updated dependencies [[`2f54f5b`](https://github.com/cypress-io/cypress-design/commit/2f54f5b867b60ba5ce2e40fd38870bd65187ba30), [`e82d8cb`](https://github.com/cypress-io/cypress-design/commit/e82d8cb60882a379d89f86d1ff7b8f1d5b56ce66)]:
39
+ - @cypress-design/react-icon@0.11.0
40
+
41
+ ## 0.4.4
42
+
43
+ ### Patch Changes
44
+
45
+ - [#101](https://github.com/cypress-io/cypress-design/pull/101) [`1630e4c`](https://github.com/cypress-io/cypress-design/commit/1630e4c4200944cf6414cee9e92dcce6b4d8a576) Thanks [@mapsandapps](https://github.com/mapsandapps)! - Fix styles for Checkbox
46
+
47
+ ## 0.4.3
48
+
49
+ ### Patch Changes
50
+
51
+ - [#71](https://github.com/cypress-io/cypress-design/pull/71) [`379079e`](https://github.com/cypress-io/cypress-design/commit/379079e08802b6c3fae243925e3b9e8881e8ef54) Thanks [@elevatebart](https://github.com/elevatebart)! - allow users to click the checkbox instead of the label
52
+
53
+ ## 0.4.2
54
+
55
+ ### Patch Changes
56
+
57
+ - [#68](https://github.com/cypress-io/cypress-design/pull/68) [`8c577fb`](https://github.com/cypress-io/cypress-design/commit/8c577fb0c6a0411cf8218dfe78281834df3d6f13) Thanks [@elevatebart](https://github.com/elevatebart)! - feat: publish `.mjs` files for esm intead of `.js`
58
+
59
+ - Updated dependencies [[`8c577fb`](https://github.com/cypress-io/cypress-design/commit/8c577fb0c6a0411cf8218dfe78281834df3d6f13)]:
60
+ - @cypress-design/react-icon@0.4.2
61
+
62
+ ## 0.4.1
63
+
64
+ ### Patch Changes
65
+
66
+ - [`2afa4d5`](https://github.com/cypress-io/cypress-design/commit/2afa4d54a2373692f82bee35ae40446bc9bb3f91) Thanks [@elevatebart](https://github.com/elevatebart)! - avoid duplicate ids in checkboxes
67
+
68
+ ## 0.4.0
69
+
70
+ ### Minor Changes
71
+
72
+ - [#51](https://github.com/cypress-io/cypress-design/pull/51) [`ccd8f9a`](https://github.com/cypress-io/cypress-design/commit/ccd8f9a8feb624c0a52deaa9754c76969f43fc1e) Thanks [@elevatebart](https://github.com/elevatebart)! - in the build asset, add a comment containing all used windicss classes in the component
73
+
74
+ ### Patch Changes
75
+
76
+ - [#57](https://github.com/cypress-io/cypress-design/pull/57) [`6fa7d52`](https://github.com/cypress-io/cypress-design/commit/6fa7d52e409762bd1b32a8b04edaf78765830754) Thanks [@elevatebart](https://github.com/elevatebart)! - fix: move the input for checkboxes outside of label for accessibility
77
+
78
+ Source: https://www.a11ymatters.com/pattern/checkbox/
79
+
80
+ - Updated dependencies [[`ccd8f9a`](https://github.com/cypress-io/cypress-design/commit/ccd8f9a8feb624c0a52deaa9754c76969f43fc1e), [`0866c65`](https://github.com/cypress-io/cypress-design/commit/0866c654f24c36951c98468d789462748606b428), [`43b53eb`](https://github.com/cypress-io/cypress-design/commit/43b53eb6bd10111629239a87374cfcc894eda0e3)]:
81
+ - @cypress-design/react-icon@0.4.0
82
+
83
+ ## 0.3.0
84
+
85
+ ### Minor Changes
86
+
87
+ - [#44](https://github.com/cypress-io/cypress-design/pull/44) [`2fdaf6b`](https://github.com/cypress-io/cypress-design/commit/2fdaf6be6f81a2a851761258347ed213577c5b26) Thanks [@elevatebart](https://github.com/elevatebart)! - Add missing descriptions of props in button, tooltip, checkbox
88
+
89
+ ## 0.2.2
90
+
91
+ ### Patch Changes
92
+
93
+ - [`e3eb9c7`](https://github.com/cypress-io/cypress-design/commit/e3eb9c7fee2d7a6e0a773e85ed4b73be04d83587) Thanks [@elevatebart](https://github.com/elevatebart)! - downgrade typescript to 4.4 for compat with app
94
+
95
+ ## 0.2.1
96
+
97
+ ### Patch Changes
98
+
99
+ - [#39](https://github.com/cypress-io/cypress-design/pull/39) [`1b383f3`](https://github.com/cypress-io/cypress-design/commit/1b383f3d149948bf2cc062d3baa17d5ce032f07e) Thanks [@elevatebart](https://github.com/elevatebart)! - fix file path of sourcemaps
100
+
101
+ - Updated dependencies [[`4259026`](https://github.com/cypress-io/cypress-design/commit/4259026314464260e89bcd88690c8a60ad2f0459), [`1b383f3`](https://github.com/cypress-io/cypress-design/commit/1b383f3d149948bf2cc062d3baa17d5ce032f07e)]:
102
+ - @cypress-design/react-icon@0.3.0
103
+
104
+ ## 0.2.0
105
+
106
+ ### Minor Changes
107
+
108
+ - [#33](https://github.com/cypress-io/cypress-design/pull/33) [`5f9cf10`](https://github.com/cypress-io/cypress-design/commit/5f9cf10ff4709fcd7d322c2dc5dbc676473b433e) Thanks [@elevatebart](https://github.com/elevatebart)! - fix design and api of checkboxes
109
+
110
+ ### Patch Changes
111
+
112
+ - Updated dependencies []:
113
+ - @cypress-design/react-icon@0.2.1
114
+
3
115
  ## 0.1.0
4
116
 
5
117
  ### Minor Changes
@@ -0,0 +1,17 @@
1
+ import * as React from 'react'
2
+ import Checkbox from './Checkbox'
3
+
4
+ export default (options: {
5
+ color?: 'jade' | 'indigo' | 'red'
6
+ checked?: boolean
7
+ }) => {
8
+ const { checked = true, color } = options
9
+ return (
10
+ <Checkbox
11
+ checked={checked}
12
+ label="Checked"
13
+ color={color}
14
+ onChange={() => {}}
15
+ />
16
+ )
17
+ }
@@ -1,23 +1,67 @@
1
- import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs'
1
+ import { ArgsTable, Canvas, Meta, Story, Description } from '@storybook/addon-docs'
2
+ import { version } from "./package.json"
3
+ import changelog from "./CHANGELOG.md"
2
4
 
3
5
  import { Checkbox } from './Checkbox'
4
6
 
5
- # Checkbox
7
+ <h1>Checkbox<span className="text-lg font-normal"> - v{version}</span></h1>
6
8
 
7
- <Meta title="Checkbox" component={Checkbox} />
9
+ <Meta title="Checkbox" component={Checkbox}
10
+ argTypes={{
11
+ color: {
12
+ control: {
13
+ type: 'select',
14
+ },
15
+ },
16
+ }}
17
+ parameters={{
18
+ design: {
19
+ type: "figma",
20
+ url: 'https://www.figma.com/file/1WJ3GVQyMV5e7xVxPg3yID/Design-System?node-id=1027%3A9825',
21
+ }
22
+ }} />
8
23
 
9
- <Canvas>
24
+ <Canvas withSource="none">
10
25
  <Story name="Checkbox">
11
- <>
12
- <Checkbox modelValue={true} label="Checked" />
26
+ {args =>
27
+ (<>
28
+ <Checkbox {...args} checked label="Checked" />
13
29
  <br />
14
- <Checkbox modelValue={false} label="Unchecked" />
30
+ <Checkbox {...args} label="Unchecked" />
15
31
  <br />
16
- <Checkbox modelValue={true} disabled label="Disabled & checked" />
32
+ <Checkbox {...args} checked disabled label="Disabled & checked" />
17
33
  <br />
18
- <Checkbox modelValue={false} disabled label="Disabled & unchecked" />
19
- </>
34
+ <Checkbox {...args} disabled label="Disabled & unchecked" />
35
+ </>)}
20
36
  </Story>
21
37
  </Canvas>
22
38
 
23
39
  <ArgsTable />
40
+
41
+ ## Usage
42
+
43
+ Install the component
44
+
45
+ ```
46
+ yarn add @cypress-design/react-checkbox
47
+ ```
48
+
49
+ In the script, import the component
50
+
51
+ ```js
52
+ import Checkbox from '@cypress-design/react-checkbox'
53
+ ```
54
+
55
+ then in your render function, use it
56
+
57
+ ```jsx
58
+ export const MyComp = () => {
59
+ return (<div>
60
+ <Checkbox checked={checked} label="Checked" color="indigo" onChange={setChecked}/>
61
+ </div>)
62
+ }
63
+ ```
64
+
65
+ <Description>
66
+ {changelog.replace(/^# .+/, '## Changelog')}
67
+ </Description>
package/Checkbox.tsx CHANGED
@@ -1,60 +1,105 @@
1
- import * as React from 'react';
2
- import type { FunctionComponent, HTMLProps, ReactNode } from 'react';
1
+ import clsx from 'clsx'
2
+ import * as React from 'react'
3
+ import type { FunctionComponent, HTMLProps, ReactNode } from 'react'
4
+ import { IconCheckmarkSmall } from '@cypress-design/react-icon'
5
+ import { CheckboxColors, Classes } from '../constants'
3
6
 
4
7
  export interface CheckboxProps
5
- extends Omit<HTMLProps<HTMLDivElement>, 'label'> {
6
- id?: string;
7
- modelValue: boolean;
8
- onChange: () => void;
9
- state?: 'success' | 'danger' | 'default';
10
- label?: ReactNode;
8
+ extends Omit<HTMLProps<HTMLDivElement>, 'label' | 'onChange' | 'name'> {
9
+ /**
10
+ * A unique identifier for the checkbox on the whole page.
11
+ * It will be used to give match label with input for a11y.
12
+ */
13
+ id?: string
14
+ /**
15
+ * Name attribute of the <input type="checkbox"/>.
16
+ */
17
+ name?: string
18
+ /**
19
+ * Is the checkbox checked when it is first rendered.
20
+ */
21
+ checked?: boolean
22
+ /**
23
+ * The color of the background in the checkbox.
24
+ * The checkmark will always be white.
25
+ */
26
+ color?: 'red' | 'indigo' | 'jade'
27
+ /**
28
+ * If the checkbox is disabled, it will not be clickable.
29
+ */
30
+ disabled?: boolean
31
+ /**
32
+ * Label for the checkbox.
33
+ * It is very important to set this to make the checkbox accessible.
34
+ */
35
+ label?: ReactNode
36
+ onChange: (event: React.ChangeEvent<HTMLInputElement>) => void
11
37
  }
12
38
 
13
- // TODO: how do you disable it? does it work?
39
+ const uid = () =>
40
+ String(Date.now().toString(32) + Math.random().toString(16)).replace(
41
+ /\./g,
42
+ ''
43
+ )
44
+
14
45
  export const Checkbox: FunctionComponent<CheckboxProps> = ({
15
- id = crypto.randomUUID(),
16
- modelValue,
46
+ id = uid(),
47
+ checked = false,
17
48
  onChange,
18
- state = 'default',
49
+ color = 'indigo',
19
50
  label,
51
+ disabled,
52
+ className,
53
+ name,
20
54
  ...rest
21
55
  }) => {
56
+ const [localChecked, setChecked] = React.useState(checked)
57
+
58
+ function onChangeInput(event: React.ChangeEvent<HTMLInputElement>) {
59
+ setChecked(!localChecked)
60
+ onChange(event)
61
+ }
62
+
22
63
  return (
23
- <div {...rest} className="relative flex items-center">
24
- <div className="flex items-center h-5">
25
- <input
26
- id={id}
27
- defaultChecked={modelValue}
28
- aria-describedby={`${id}-description`}
29
- name={id}
30
- type="checkbox"
31
- className={`border-1 rounded border-gray-200 bg-white h-4 w-4 text-indigo-500 disabled:bg-gray-100 checked:bg-indigo-500 ${
32
- state === 'default'
33
- ? 'text-indigo-500 checked:border-indigo-300 checked:bg-indigo-600 checked:text-indigo-600'
34
- : ''
35
- } ${
36
- state === 'success'
37
- ? 'checked:border-jade-300 checked:bg-jade-600 checked:text-jade-600'
38
- : ''
39
- } ${
40
- state === 'danger'
41
- ? 'checked:border-red-300 checked:bg-red-600 checked:text-red-600'
42
- : ''
43
- }`}
44
- onChange={onChange}
64
+ <span className={clsx(className, Classes.wrapper)} {...rest}>
65
+ <input
66
+ id={id}
67
+ className={Classes.hiddenInput}
68
+ aria-describedby={`${id}-description`}
69
+ name={name || id}
70
+ type="checkbox"
71
+ onChange={onChangeInput}
72
+ disabled={disabled}
73
+ checked={localChecked}
74
+ />
75
+ <label className={Classes.labelTag} htmlFor={id}>
76
+ {localChecked && (
77
+ // <tw-keep strokeColor="white"/>
78
+ <IconCheckmarkSmall strokeColor="white" className="absolute" />
79
+ )}
80
+ <span
81
+ className={clsx([
82
+ Classes.visibleCheckbox,
83
+ disabled
84
+ ? CheckboxColors.disabled
85
+ : localChecked
86
+ ? CheckboxColors[color]
87
+ : CheckboxColors.empty,
88
+ ])}
45
89
  />
46
- </div>
47
- <div className="ml-2 text-16px leading-normal">
48
- <label
49
- v-if="label"
50
- htmlFor={id}
51
- className="disabled:text-gray-500 text-gray-800 font-light select-none"
52
- >
53
- {label}
54
- </label>
55
- </div>
56
- </div>
57
- );
58
- };
90
+ {label && (
91
+ <span
92
+ className={clsx([
93
+ disabled ? 'text-gray-500' : 'text-gray-800',
94
+ Classes.trueLabel,
95
+ ])}
96
+ >
97
+ {label}
98
+ </span>
99
+ )}
100
+ </label>
101
+ </span>
102
+ )
103
+ }
59
104
 
60
- export default Checkbox;
105
+ export default Checkbox
@@ -0,0 +1,64 @@
1
+ import * as React from 'react'
2
+ import { mount } from 'cypress/react'
3
+ import { Checkbox } from './Checkbox'
4
+
5
+ describe('Checkbox', () => {
6
+ it('changes when the label is clicked', () => {
7
+ let isChecked = true
8
+
9
+ mount(
10
+ <Checkbox
11
+ label="Welcome guide settings"
12
+ id="welcome-opt-out"
13
+ checked={isChecked}
14
+ onChange={() => (isChecked = !isChecked)}
15
+ className="px-2 py-1 m-2 border border-gray-300 rounded"
16
+ />
17
+ )
18
+
19
+ cy.get('input[type="checkbox"]').should('be.checked')
20
+ cy.percySnapshot()
21
+ cy.contains('Welcome guide settings').click()
22
+ cy.get('input[type="checkbox"]').should('not.be.checked')
23
+ cy.percySnapshot()
24
+ })
25
+
26
+ it('changes when checkbox is clicked', () => {
27
+ let isChecked = true
28
+
29
+ mount(
30
+ <Checkbox
31
+ label="Welcome guide settings"
32
+ id="welcome-opt-out"
33
+ checked={isChecked}
34
+ onChange={() => (isChecked = !isChecked)}
35
+ className="px-2 py-1 m-2 border border-gray-300 rounded"
36
+ />
37
+ )
38
+
39
+ cy.get('input[type="checkbox"]').should('be.checked')
40
+ cy.get('svg').click()
41
+ cy.get('input[type="checkbox"]').should('not.be.checked')
42
+ })
43
+
44
+ it('keeps its width when label is long', () => {
45
+ mount(
46
+ <Checkbox
47
+ label={[
48
+ 'lorem ipsum dolor sit amet, consectetur adipiscing elit,',
49
+ 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
50
+ 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip',
51
+ 'ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse',
52
+ 'cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,',
53
+ 'sunt in culpa qui officia deserunt mollit anim id est laborum.',
54
+ ].join(' ')}
55
+ id="lorem-checkbox"
56
+ onChange={() => {}}
57
+ />
58
+ )
59
+
60
+ cy.percySnapshot()
61
+
62
+ cy.get('label span:first-child').invoke('outerWidth').should('equal', 16)
63
+ })
64
+ })
package/ReadMe.md ADDED
@@ -0,0 +1,17 @@
1
+ # Checkbox
2
+
3
+ ## Summary
4
+
5
+ Describe your component here.
6
+
7
+ ## install
8
+
9
+ ```bash
10
+ npm install @cypress-design/react-checkbox
11
+ ```
12
+
13
+ or with yarn
14
+
15
+ ```bash
16
+ yarn add @cypress-design/react-checkbox
17
+ ```
@@ -0,0 +1,15 @@
1
+ export declare const Classes: {
2
+ wrapper: string;
3
+ hiddenInput: string;
4
+ labelTag: string;
5
+ visibleCheckbox: string;
6
+ trueLabel: string;
7
+ };
8
+ export declare const CheckboxColors: {
9
+ readonly indigo: "border-indigo-500 bg-indigo-400";
10
+ readonly jade: "border-jade-500 bg-jade-400";
11
+ readonly red: "border-red-500 bg-red-400";
12
+ readonly disabled: "border-gray-200 bg-gray-100";
13
+ readonly empty: "border-gray-200 bg-white";
14
+ };
15
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO;;;;;;CAOnB,CAAA;AAED,eAAO,MAAM,cAAc;;;;;;CAMjB,CAAA"}
@@ -0,0 +1,164 @@
1
+ import clsx from 'clsx';
2
+ import * as React from 'react';
3
+ import * as iconsRegistry from '@cypress-design/icon-registry';
4
+ import { ICON_COLOR_PROP_NAMES } from '@cypress-design/icon-registry';
5
+
6
+ /******************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+
21
+ var __assign$1 = function() {
22
+ __assign$1 = Object.assign || function __assign(t) {
23
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
24
+ s = arguments[i];
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
26
+ }
27
+ return t;
28
+ };
29
+ return __assign$1.apply(this, arguments);
30
+ };
31
+
32
+ function __rest$1(s, e) {
33
+ var t = {};
34
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
35
+ t[p] = s[p];
36
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
37
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
38
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
39
+ t[p[i]] = s[p[i]];
40
+ }
41
+ return t;
42
+ }
43
+
44
+ /******************************************************************************
45
+ Copyright (c) Microsoft Corporation.
46
+
47
+ Permission to use, copy, modify, and/or distribute this software for any
48
+ purpose with or without fee is hereby granted.
49
+
50
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
51
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
52
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
53
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
54
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
55
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
56
+ PERFORMANCE OF THIS SOFTWARE.
57
+ ***************************************************************************** */
58
+
59
+ var __assign = function() {
60
+ __assign = Object.assign || function __assign(t) {
61
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
62
+ s = arguments[i];
63
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
64
+ }
65
+ return t;
66
+ };
67
+ return __assign.apply(this, arguments);
68
+ };
69
+
70
+ function __rest(s, e) {
71
+ var t = {};
72
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
73
+ t[p] = s[p];
74
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
75
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
76
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
77
+ t[p[i]] = s[p[i]];
78
+ }
79
+ return t;
80
+ }
81
+
82
+ var compileReactIconProperties = function (_a) {
83
+ var body = _a.body, compiledClasses = _a.compiledClasses, size = _a.size, attributes = __rest(_a, ["body", "compiledClasses", "size"]);
84
+ var filteredAttributes = Object.keys(attributes).reduce(function (newAttributes, attrName) {
85
+ if (!ICON_COLOR_PROP_NAMES.includes(attrName) && attrName !== 'name') {
86
+ newAttributes[attrName] =
87
+ attributes[attrName];
88
+ }
89
+ return newAttributes;
90
+ }, {});
91
+ var componentProps = __assign({ width: size, height: size, viewBox: "0 0 " + size + " " + size, fill: 'none', dangerouslySetInnerHTML: {
92
+ __html: body
93
+ } }, filteredAttributes);
94
+ if (attributes.className) {
95
+ compiledClasses.push(attributes.className);
96
+ }
97
+ if (compiledClasses.length) {
98
+ componentProps.className = compiledClasses.join(' ');
99
+ }
100
+ return componentProps;
101
+ };
102
+ var IconCheckmarkSmall = function (props) {
103
+ var _a = iconsRegistry.getComponentAttributes(__assign(__assign({}, props), { availableSizes: ["16"] })), size = _a.sizeWithDefault, compiledClasses = _a.compiledClasses;
104
+ var iconBodies = {
105
+ "16": "<path d=\"M5 8.5 7.5 11 11 5\" stroke=\"currentColor\" class=\"icon-dark\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>"
106
+ };
107
+ var body = iconBodies[size];
108
+ if (!body) {
109
+ throw Error("Icon \"checkmark-small\" is not available in size " + size);
110
+ }
111
+ return React.createElement('svg', compileReactIconProperties(__assign(__assign({}, props), { size: size, body: body, compiledClasses: compiledClasses })));
112
+ };
113
+
114
+ /* <windicss-keep class=""> */
115
+
116
+ var Classes = {
117
+ wrapper: 'relative flex items-center',
118
+ hiddenInput: 'absolute inset-0 w-0 h-0 opacity-0',
119
+ labelTag: 'flex items-center',
120
+ visibleCheckbox: 'border border-solid rounded h-[16px] w-[16px] flex flex-shrink-0 items-center text-white',
121
+ trueLabel: 'block ml-[8px] text-[16px] leading-[24px] font-light select-none'
122
+ };
123
+ var CheckboxColors = {
124
+ indigo: 'border-indigo-500 bg-indigo-400',
125
+ jade: 'border-jade-500 bg-jade-400',
126
+ red: 'border-red-500 bg-red-400',
127
+ disabled: 'border-gray-200 bg-gray-100',
128
+ empty: 'border-gray-200 bg-white'
129
+ };
130
+
131
+ var uid = function () {
132
+ return String(Date.now().toString(32) + Math.random().toString(16)).replace(/\./g, '');
133
+ };
134
+ var Checkbox = function (_a) {
135
+ var _b = _a.id, id = _b === void 0 ? uid() : _b, _c = _a.checked, checked = _c === void 0 ? false : _c, onChange = _a.onChange, _d = _a.color, color = _d === void 0 ? 'indigo' : _d, label = _a.label, disabled = _a.disabled, className = _a.className, name = _a.name, rest = __rest$1(_a, ["id", "checked", "onChange", "color", "label", "disabled", "className", "name"]);
136
+ var _e = React.useState(checked), localChecked = _e[0], setChecked = _e[1];
137
+ function onChangeInput(event) {
138
+ setChecked(!localChecked);
139
+ onChange(event);
140
+ }
141
+ return (React.createElement("span", __assign$1({ className: clsx(className, Classes.wrapper) }, rest),
142
+ React.createElement("input", { id: id, className: Classes.hiddenInput, "aria-describedby": id + "-description", name: name || id, type: "checkbox", onChange: onChangeInput, disabled: disabled, checked: localChecked }),
143
+ React.createElement("label", { className: Classes.labelTag, htmlFor: id },
144
+ localChecked && (
145
+ // <tw-keep strokeColor="white"/>
146
+ React.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
147
+ React.createElement("span", { className: clsx([
148
+ Classes.visibleCheckbox,
149
+ disabled
150
+ ? CheckboxColors.disabled
151
+ : localChecked
152
+ ? CheckboxColors[color]
153
+ : CheckboxColors.empty,
154
+ ]) }),
155
+ label && (React.createElement("span", { className: clsx([
156
+ disabled ? 'text-gray-500' : 'text-gray-800',
157
+ Classes.trueLabel,
158
+ ]) }, label)))));
159
+ };
160
+
161
+ export { Checkbox as default };
162
+
163
+ /* <windicss-keep class="absolute text-gray-500 text-gray-800 icon-dark-white relative flex items-center inset-0 w-0 h-0 opacity-0 border border-solid rounded h-[16px] w-[16px] flex-shrink-0 text-white block ml-[8px] text-[16px] leading-[24px] font-light select-none border-indigo-500 bg-indigo-400 border-jade-500 bg-jade-400 border-red-500 bg-red-400 border-gray-200 bg-gray-100 bg-white"> */
164
+ //# sourceMappingURL=index.es.mjs.map