@cypress-design/react-checkbox 0.4.2 → 0.4.3

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,11 @@
1
1
  # @cypress-design/react-checkbox
2
2
 
3
+ ## 0.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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
8
+
3
9
  ## 0.4.2
4
10
 
5
11
  ### Patch Changes
package/Checkbox.tsx CHANGED
@@ -71,24 +71,24 @@ export const Checkbox: FunctionComponent<CheckboxProps> = ({
71
71
  disabled={disabled}
72
72
  checked={localChecked}
73
73
  />
74
- {localChecked && (
75
- <IconCheckmarkSmall strokeColor="white" className="absolute" />
76
- )}
77
- <span
78
- className={clsx([
79
- `block border-1 rounded h-16px w-16px flex items-center text-white`,
80
- disabled
81
- ? 'border-gray-200 bg-gray-100'
82
- : localChecked
83
- ? {
84
- 'border-indigo-500 bg-indigo-400': color === 'indigo',
85
- 'border-jade-500 bg-jade-400': color === 'jade',
86
- 'border-red-500 bg-red-400': color === 'red',
87
- }
88
- : 'border-gray-200 bg-white',
89
- ])}
90
- />
91
- <label htmlFor={id}>
74
+ <label className="flex items-center" htmlFor={id}>
75
+ {localChecked && (
76
+ <IconCheckmarkSmall strokeColor="white" className="absolute" />
77
+ )}
78
+ <span
79
+ className={clsx([
80
+ `block border-1 rounded h-16px w-16px flex items-center text-white`,
81
+ disabled
82
+ ? 'border-gray-200 bg-gray-100'
83
+ : localChecked
84
+ ? {
85
+ 'border-indigo-500 bg-indigo-400': color === 'indigo',
86
+ 'border-jade-500 bg-jade-400': color === 'jade',
87
+ 'border-red-500 bg-red-400': color === 'red',
88
+ }
89
+ : 'border-gray-200 bg-white',
90
+ ])}
91
+ />
92
92
  {label && (
93
93
  <span
94
94
  className={clsx([
@@ -3,7 +3,7 @@ import { mount } from 'cypress/react'
3
3
  import { Checkbox } from './Checkbox'
4
4
 
5
5
  describe('Checkbox', () => {
6
- it('renders', () => {
6
+ it('changes when the label is clicked', () => {
7
7
  let isChecked = true
8
8
 
9
9
  mount(
@@ -20,4 +20,22 @@ describe('Checkbox', () => {
20
20
  cy.contains('Welcome guide settings').click()
21
21
  cy.get('input[type="checkbox"]').should('not.be.checked')
22
22
  })
23
+
24
+ it('changes when checkbox is clicked', () => {
25
+ let isChecked = true
26
+
27
+ mount(
28
+ <Checkbox
29
+ label="Welcome guide settings"
30
+ id="welcome-opt-out"
31
+ checked={isChecked}
32
+ onChange={() => (isChecked = !isChecked)}
33
+ className="m-2 px-2 py-1 border-1 border-gray-300 rounded"
34
+ />
35
+ )
36
+
37
+ cy.get('input[type="checkbox"]').should('be.checked')
38
+ cy.get('svg').click()
39
+ cy.get('input[type="checkbox"]').should('not.be.checked')
40
+ })
23
41
  })
package/dist/index.es.mjs CHANGED
@@ -125,23 +125,24 @@ var Checkbox = function (_a) {
125
125
  }
126
126
  return (React.createElement("div", __assign$1({ className: clsx(className, 'relative flex items-center') }, rest),
127
127
  React.createElement("input", { id: id, className: "absolute inset-0 w-0 h-0 opacity-0", "aria-describedby": id + "-description", name: name || id, type: "checkbox", onChange: onChangeInput, disabled: disabled, checked: localChecked }),
128
- localChecked && (React.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
129
- React.createElement("span", { className: clsx([
130
- "block border-1 rounded h-16px w-16px flex items-center text-white",
131
- disabled
132
- ? 'border-gray-200 bg-gray-100'
133
- : localChecked
134
- ? {
135
- 'border-indigo-500 bg-indigo-400': color === 'indigo',
136
- 'border-jade-500 bg-jade-400': color === 'jade',
137
- 'border-red-500 bg-red-400': color === 'red'
138
- }
139
- : 'border-gray-200 bg-white',
140
- ]) }),
141
- React.createElement("label", { htmlFor: id }, label && (React.createElement("span", { className: clsx([
142
- disabled ? 'text-gray-500' : 'text-gray-800',
143
- 'block ml-2 text-16px leading-normal font-light select-none',
144
- ]) }, label)))));
128
+ React.createElement("label", { className: "flex items-center", htmlFor: id },
129
+ localChecked && (React.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
130
+ React.createElement("span", { className: clsx([
131
+ "block border-1 rounded h-16px w-16px flex items-center text-white",
132
+ disabled
133
+ ? 'border-gray-200 bg-gray-100'
134
+ : localChecked
135
+ ? {
136
+ 'border-indigo-500 bg-indigo-400': color === 'indigo',
137
+ 'border-jade-500 bg-jade-400': color === 'jade',
138
+ 'border-red-500 bg-red-400': color === 'red'
139
+ }
140
+ : 'border-gray-200 bg-white',
141
+ ]) }),
142
+ label && (React.createElement("span", { className: clsx([
143
+ disabled ? 'text-gray-500' : 'text-gray-800',
144
+ 'block ml-2 text-16px leading-normal font-light select-none',
145
+ ]) }, label)))));
145
146
  };
146
147
 
147
148
  export { Checkbox as default };