@seed-design/react-checkbox 0.0.4 → 1.0.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.
@@ -4,6 +4,7 @@ import { elementProps, dataAttr, inputProps, labelProps, visuallyHidden, mergePr
4
4
  import { Primitive } from '@seed-design/react-primitive';
5
5
  import { useState, useRef, useEffect, createContext, useContext, forwardRef } from 'react';
6
6
  import { useControllableState } from '@radix-ui/react-use-controllable-state';
7
+ import { useSupports } from '@seed-design/react-supports';
7
8
  import { composeRefs } from '@radix-ui/react-compose-refs';
8
9
 
9
10
  function useCheckboxState(props) {
@@ -53,6 +54,7 @@ function useCheckboxState(props) {
53
54
  }
54
55
  function useCheckbox(props) {
55
56
  const { refs, isIndeterminate, setIsChecked, isChecked, setIsHovered, isHovered, setIsActive, isActive, setIsFocused, isFocused, setIsFocusVisible, isFocusVisible } = useCheckboxState(props);
57
+ const isFocusVisibleSupported = useSupports("selector(:focus-visible)");
56
58
  const stateProps = elementProps({
57
59
  "data-checked": dataAttr(isChecked),
58
60
  "data-indeterminate": dataAttr(isIndeterminate),
@@ -107,15 +109,21 @@ function useCheckbox(props) {
107
109
  ...stateProps,
108
110
  onChange (event) {
109
111
  setIsChecked(event.currentTarget.checked);
110
- setIsFocusVisible(event.target.matches(":focus-visible"));
112
+ if (isFocusVisibleSupported) {
113
+ setIsFocusVisible(event.target.matches(":focus-visible"));
114
+ }
111
115
  },
112
116
  onFocus (event) {
113
117
  setIsFocused(true);
114
- setIsFocusVisible(event.target.matches(":focus-visible"));
118
+ if (isFocusVisibleSupported) {
119
+ setIsFocusVisible(event.target.matches(":focus-visible"));
120
+ }
115
121
  },
116
122
  onBlur () {
117
123
  setIsFocused(false);
118
- setIsFocusVisible(false);
124
+ if (isFocusVisibleSupported) {
125
+ setIsFocusVisible(false);
126
+ }
119
127
  },
120
128
  onKeyDown (event) {
121
129
  if (event.key === " ") {
@@ -4,6 +4,7 @@ var domUtils = require('@seed-design/dom-utils');
4
4
  var reactPrimitive = require('@seed-design/react-primitive');
5
5
  var react = require('react');
6
6
  var reactUseControllableState = require('@radix-ui/react-use-controllable-state');
7
+ var reactSupports = require('@seed-design/react-supports');
7
8
  var reactComposeRefs = require('@radix-ui/react-compose-refs');
8
9
 
9
10
  function useCheckboxState(props) {
@@ -53,6 +54,7 @@ function useCheckboxState(props) {
53
54
  }
54
55
  function useCheckbox(props) {
55
56
  const { refs, isIndeterminate, setIsChecked, isChecked, setIsHovered, isHovered, setIsActive, isActive, setIsFocused, isFocused, setIsFocusVisible, isFocusVisible } = useCheckboxState(props);
57
+ const isFocusVisibleSupported = reactSupports.useSupports("selector(:focus-visible)");
56
58
  const stateProps = domUtils.elementProps({
57
59
  "data-checked": domUtils.dataAttr(isChecked),
58
60
  "data-indeterminate": domUtils.dataAttr(isIndeterminate),
@@ -107,15 +109,21 @@ function useCheckbox(props) {
107
109
  ...stateProps,
108
110
  onChange (event) {
109
111
  setIsChecked(event.currentTarget.checked);
110
- setIsFocusVisible(event.target.matches(":focus-visible"));
112
+ if (isFocusVisibleSupported) {
113
+ setIsFocusVisible(event.target.matches(":focus-visible"));
114
+ }
111
115
  },
112
116
  onFocus (event) {
113
117
  setIsFocused(true);
114
- setIsFocusVisible(event.target.matches(":focus-visible"));
118
+ if (isFocusVisibleSupported) {
119
+ setIsFocusVisible(event.target.matches(":focus-visible"));
120
+ }
115
121
  },
116
122
  onBlur () {
117
123
  setIsFocused(false);
118
- setIsFocusVisible(false);
124
+ if (isFocusVisibleSupported) {
125
+ setIsFocusVisible(false);
126
+ }
119
127
  },
120
128
  onKeyDown (event) {
121
129
  if (event.key === " ") {
package/lib/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- var Checkbox12s = require('./Checkbox-12s-Y3jZEb8V.cjs');
1
+ var Checkbox12s = require('./Checkbox-12s-B9wGaaeq.cjs');
2
2
 
3
3
  var Checkbox_namespace = {
4
4
  __proto__: null,
package/lib/index.d.ts CHANGED
@@ -72,7 +72,7 @@ declare function useCheckbox(props: UseCheckboxProps): {
72
72
  results?: number | undefined | undefined;
73
73
  security?: string | undefined | undefined;
74
74
  unselectable?: "on" | "off" | undefined | undefined;
75
- popover?: "" | "auto" | "manual" | undefined | undefined;
75
+ popover?: "" | "auto" | "manual" | "hint" | undefined | undefined;
76
76
  popoverTargetAction?: "toggle" | "show" | "hide" | undefined | undefined;
77
77
  popoverTarget?: string | undefined | undefined;
78
78
  inert?: boolean | undefined | undefined;
@@ -354,7 +354,7 @@ declare function useCheckbox(props: UseCheckboxProps): {
354
354
  results?: number | undefined | undefined;
355
355
  security?: string | undefined | undefined;
356
356
  unselectable?: "on" | "off" | undefined | undefined;
357
- popover?: "" | "auto" | "manual" | undefined | undefined;
357
+ popover?: "" | "auto" | "manual" | "hint" | undefined | undefined;
358
358
  popoverTargetAction?: "toggle" | "show" | "hide" | undefined | undefined;
359
359
  popoverTarget?: string | undefined | undefined;
360
360
  inert?: boolean | undefined | undefined;
@@ -638,7 +638,7 @@ declare function useCheckbox(props: UseCheckboxProps): {
638
638
  results?: number | undefined | undefined;
639
639
  security?: string | undefined | undefined;
640
640
  unselectable?: "on" | "off" | undefined | undefined;
641
- popover?: "" | "auto" | "manual" | undefined | undefined;
641
+ popover?: "" | "auto" | "manual" | "hint" | undefined | undefined;
642
642
  popoverTargetAction?: "toggle" | "show" | "hide" | undefined | undefined;
643
643
  popoverTarget?: string | undefined | undefined;
644
644
  inert?: boolean | undefined | undefined;
@@ -923,7 +923,7 @@ declare function useCheckbox(props: UseCheckboxProps): {
923
923
  results?: number | undefined | undefined;
924
924
  security?: string | undefined | undefined;
925
925
  unselectable?: "on" | "off" | undefined | undefined;
926
- popover?: "" | "auto" | "manual" | undefined | undefined;
926
+ popover?: "" | "auto" | "manual" | "hint" | undefined | undefined;
927
927
  popoverTargetAction?: "toggle" | "show" | "hide" | undefined | undefined;
928
928
  popoverTarget?: string | undefined | undefined;
929
929
  inert?: boolean | undefined | undefined;
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CheckboxControl, a as CheckboxHiddenInput, b as CheckboxRoot } from './Checkbox-12s-BeV5Lkaw.js';
2
- export { u as useCheckboxContext } from './Checkbox-12s-BeV5Lkaw.js';
1
+ import { C as CheckboxControl, a as CheckboxHiddenInput, b as CheckboxRoot } from './Checkbox-12s-B22GIIyy.js';
2
+ export { u as useCheckboxContext } from './Checkbox-12s-B22GIIyy.js';
3
3
 
4
4
  var Checkbox_namespace = {
5
5
  __proto__: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-design/react-checkbox",
3
- "version": "0.0.4",
3
+ "version": "1.0.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/daangn/seed-design.git",
@@ -29,8 +29,9 @@
29
29
  "dependencies": {
30
30
  "@radix-ui/react-compose-refs": "^1.1.2",
31
31
  "@radix-ui/react-use-controllable-state": "1.2.2",
32
- "@seed-design/dom-utils": "0.0.2",
33
- "@seed-design/react-primitive": "0.0.3"
32
+ "@seed-design/dom-utils": "1.0.0",
33
+ "@seed-design/react-primitive": "1.0.0",
34
+ "@seed-design/react-supports": "0.0.1"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@types/react": "^19.1.6",
@@ -32,6 +32,11 @@ function Checkbox(props: CheckboxRootProps) {
32
32
  }
33
33
 
34
34
  describe("useCheckbox", () => {
35
+ global.CSS = {
36
+ // @ts-expect-error
37
+ supports: (_k, _v) => true,
38
+ };
39
+
35
40
  it("should render the checkbox correctly", () => {
36
41
  const { getByRole } = setUp(<Checkbox />);
37
42
  const checkbox = getByRole("checkbox");
@@ -8,6 +8,7 @@ import {
8
8
  labelProps,
9
9
  visuallyHidden,
10
10
  } from "@seed-design/dom-utils";
11
+ import { useSupports } from "@seed-design/react-supports";
11
12
 
12
13
  interface UseCheckboxStateProps {
13
14
  checked?: boolean;
@@ -89,6 +90,8 @@ export function useCheckbox(props: UseCheckboxProps) {
89
90
  isFocusVisible,
90
91
  } = useCheckboxState(props);
91
92
 
93
+ const isFocusVisibleSupported = useSupports("selector(:focus-visible)");
94
+
92
95
  const stateProps = elementProps({
93
96
  "data-checked": dataAttr(isChecked),
94
97
  "data-indeterminate": dataAttr(isIndeterminate),
@@ -148,15 +151,21 @@ export function useCheckbox(props: UseCheckboxProps) {
148
151
  ...stateProps,
149
152
  onChange(event) {
150
153
  setIsChecked(event.currentTarget.checked);
151
- setIsFocusVisible(event.target.matches(":focus-visible"));
154
+ if (isFocusVisibleSupported) {
155
+ setIsFocusVisible(event.target.matches(":focus-visible"));
156
+ }
152
157
  },
153
158
  onFocus(event) {
154
159
  setIsFocused(true);
155
- setIsFocusVisible(event.target.matches(":focus-visible"));
160
+ if (isFocusVisibleSupported) {
161
+ setIsFocusVisible(event.target.matches(":focus-visible"));
162
+ }
156
163
  },
157
164
  onBlur() {
158
165
  setIsFocused(false);
159
- setIsFocusVisible(false);
166
+ if (isFocusVisibleSupported) {
167
+ setIsFocusVisible(false);
168
+ }
160
169
  },
161
170
  onKeyDown(event) {
162
171
  if (event.key === " ") {
@@ -9,7 +9,9 @@ export const CheckboxProvider = CheckboxContext.Provider;
9
9
 
10
10
  export function useCheckboxContext<T extends boolean | undefined = true>({
11
11
  strict = true,
12
- }: { strict?: T } = {}): T extends false ? UseCheckboxContext | null : UseCheckboxContext {
12
+ }: {
13
+ strict?: T;
14
+ } = {}): T extends false ? UseCheckboxContext | null : UseCheckboxContext {
13
15
  const context = useContext(CheckboxContext);
14
16
  if (!context && strict) {
15
17
  throw new Error("useCheckboxContext must be used within a Checkbox");