@primer/react 0.0.0-20260223174439 → 0.0.0-20260223175050

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.
@@ -1,3 +1,4 @@
1
+ import { c } from 'react-compiler-runtime';
1
2
  import { clsx } from 'clsx';
2
3
  import React, { useContext, useEffect } from 'react';
3
4
  import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
@@ -10,63 +11,170 @@ import { useProvidedRefOrCreate } from '../hooks/useProvidedRefOrCreate.js';
10
11
  /**
11
12
  * An accessible, native checkbox component
12
13
  */
13
- const Checkbox = /*#__PURE__*/React.forwardRef(({
14
- checked,
15
- className,
16
- defaultChecked,
17
- indeterminate,
18
- disabled,
19
- onChange,
20
- required,
21
- validationStatus,
22
- value,
23
- ...rest
24
- }, ref
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- ) => {
14
+ const Checkbox = /*#__PURE__*/React.forwardRef((t0, ref) => {
15
+ const $ = c(40);
16
+ let checked;
17
+ let className;
18
+ let defaultChecked;
19
+ let disabled;
20
+ let indeterminate;
21
+ let onChange;
22
+ let required;
23
+ let rest;
24
+ let validationStatus;
25
+ let value;
26
+ if ($[0] !== t0) {
27
+ ({
28
+ checked,
29
+ className,
30
+ defaultChecked,
31
+ indeterminate,
32
+ disabled,
33
+ onChange,
34
+ required,
35
+ validationStatus,
36
+ value,
37
+ ...rest
38
+ } = t0);
39
+ $[0] = t0;
40
+ $[1] = checked;
41
+ $[2] = className;
42
+ $[3] = defaultChecked;
43
+ $[4] = disabled;
44
+ $[5] = indeterminate;
45
+ $[6] = onChange;
46
+ $[7] = required;
47
+ $[8] = rest;
48
+ $[9] = validationStatus;
49
+ $[10] = value;
50
+ } else {
51
+ checked = $[1];
52
+ className = $[2];
53
+ defaultChecked = $[3];
54
+ disabled = $[4];
55
+ indeterminate = $[5];
56
+ onChange = $[6];
57
+ required = $[7];
58
+ rest = $[8];
59
+ validationStatus = $[9];
60
+ value = $[10];
61
+ }
27
62
  const checkboxRef = useProvidedRefOrCreate(ref);
28
63
  const checkboxGroupContext = useContext(CheckboxGroupContext);
29
- const handleOnChange = e => {
30
- checkboxGroupContext.onChange && checkboxGroupContext.onChange(e);
31
- onChange && onChange(e);
32
- };
33
- const inputProps = {
34
- type: 'checkbox',
35
- disabled,
36
- ref: checkboxRef,
37
- checked: indeterminate ? false : checked,
38
- defaultChecked,
39
- required,
40
- ['aria-required']: required ? 'true' : 'false',
41
- ['aria-invalid']: validationStatus === 'error' ? 'true' : 'false',
42
- onChange: handleOnChange,
43
- value,
44
- name: value,
45
- ...rest
46
- };
47
- useIsomorphicLayoutEffect(() => {
48
- if (checkboxRef.current) {
49
- checkboxRef.current.indeterminate = indeterminate || false;
50
- }
51
- }, [indeterminate, checked, checkboxRef]);
52
- useEffect(() => {
53
- const {
54
- current: checkbox
55
- } = checkboxRef;
56
- if (!checkbox) {
57
- return;
58
- }
59
- if (indeterminate) {
60
- checkbox.setAttribute('aria-checked', 'mixed');
61
- } else {
62
- checkbox.setAttribute('aria-checked', checkbox.checked ? 'true' : 'false');
63
- }
64
- });
65
- // @ts-expect-error inputProp needs a non nullable ref
66
- return /*#__PURE__*/jsx("input", {
67
- ...inputProps,
68
- className: clsx(className, sharedClasses.Input, classes.Checkbox)
69
- });
64
+ let t1;
65
+ if ($[11] !== checkboxGroupContext || $[12] !== onChange) {
66
+ t1 = e => {
67
+ checkboxGroupContext.onChange && checkboxGroupContext.onChange(e);
68
+ onChange && onChange(e);
69
+ };
70
+ $[11] = checkboxGroupContext;
71
+ $[12] = onChange;
72
+ $[13] = t1;
73
+ } else {
74
+ t1 = $[13];
75
+ }
76
+ const handleOnChange = t1;
77
+ const t2 = indeterminate ? false : checked;
78
+ const t3 = required ? "true" : "false";
79
+ const t4 = validationStatus === "error" ? "true" : "false";
80
+ let t5;
81
+ if ($[14] !== checkboxRef || $[15] !== defaultChecked || $[16] !== disabled || $[17] !== handleOnChange || $[18] !== required || $[19] !== rest || $[20] !== t2 || $[21] !== t3 || $[22] !== t4 || $[23] !== value) {
82
+ t5 = {
83
+ type: "checkbox",
84
+ disabled,
85
+ ref: checkboxRef,
86
+ checked: t2,
87
+ defaultChecked,
88
+ required,
89
+ "aria-required": t3,
90
+ "aria-invalid": t4,
91
+ onChange: handleOnChange,
92
+ value,
93
+ name: value,
94
+ ...rest
95
+ };
96
+ $[14] = checkboxRef;
97
+ $[15] = defaultChecked;
98
+ $[16] = disabled;
99
+ $[17] = handleOnChange;
100
+ $[18] = required;
101
+ $[19] = rest;
102
+ $[20] = t2;
103
+ $[21] = t3;
104
+ $[22] = t4;
105
+ $[23] = value;
106
+ $[24] = t5;
107
+ } else {
108
+ t5 = $[24];
109
+ }
110
+ const inputProps = t5;
111
+ let t6;
112
+ if ($[25] !== checkboxRef || $[26] !== indeterminate) {
113
+ t6 = () => {
114
+ if (checkboxRef.current) {
115
+ checkboxRef.current.indeterminate = indeterminate || false;
116
+ }
117
+ };
118
+ $[25] = checkboxRef;
119
+ $[26] = indeterminate;
120
+ $[27] = t6;
121
+ } else {
122
+ t6 = $[27];
123
+ }
124
+ let t7;
125
+ if ($[28] !== checkboxRef || $[29] !== checked || $[30] !== indeterminate) {
126
+ t7 = [indeterminate, checked, checkboxRef];
127
+ $[28] = checkboxRef;
128
+ $[29] = checked;
129
+ $[30] = indeterminate;
130
+ $[31] = t7;
131
+ } else {
132
+ t7 = $[31];
133
+ }
134
+ useIsomorphicLayoutEffect(t6, t7);
135
+ let t8;
136
+ if ($[32] !== checkboxRef || $[33] !== indeterminate) {
137
+ t8 = () => {
138
+ const {
139
+ current: checkbox
140
+ } = checkboxRef;
141
+ if (!checkbox) {
142
+ return;
143
+ }
144
+ if (indeterminate) {
145
+ checkbox.setAttribute("aria-checked", "mixed");
146
+ } else {
147
+ checkbox.setAttribute("aria-checked", checkbox.checked ? "true" : "false");
148
+ }
149
+ };
150
+ $[32] = checkboxRef;
151
+ $[33] = indeterminate;
152
+ $[34] = t8;
153
+ } else {
154
+ t8 = $[34];
155
+ }
156
+ useEffect(t8);
157
+ let t9;
158
+ if ($[35] !== className) {
159
+ t9 = clsx(className, sharedClasses.Input, classes.Checkbox);
160
+ $[35] = className;
161
+ $[36] = t9;
162
+ } else {
163
+ t9 = $[36];
164
+ }
165
+ let t10;
166
+ if ($[37] !== inputProps || $[38] !== t9) {
167
+ t10 = /*#__PURE__*/jsx("input", {
168
+ ...inputProps,
169
+ className: t9
170
+ });
171
+ $[37] = inputProps;
172
+ $[38] = t9;
173
+ $[39] = t10;
174
+ } else {
175
+ t10 = $[39];
176
+ }
177
+ return t10;
70
178
  });
71
179
  Checkbox.displayName = 'Checkbox';
72
180
  Checkbox.__SLOT__ = Symbol('Checkbox');