@primer/react 0.0.0-20260219201217 → 0.0.0-20260219220240

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,4 +1,3 @@
1
- import { c } from 'react-compiler-runtime';
2
1
  import React, { forwardRef } from 'react';
3
2
  import { ButtonBase } from './ButtonBase.js';
4
3
  import { TooltipContext, Tooltip } from '../TooltipV2/Tooltip.js';
@@ -7,158 +6,70 @@ import classes from './ButtonBase.module.css.js';
7
6
  import { clsx } from 'clsx';
8
7
  import { jsx } from 'react/jsx-runtime';
9
8
 
10
- const IconButton = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
11
- const $ = c(36);
12
- let Icon;
13
- let ariaLabel;
14
- let className;
15
- let description;
16
- let disabled;
17
- let keybindingHint;
18
- let keyshortcuts;
19
- let props;
20
- let t1;
21
- let tooltipDirection;
22
- if ($[0] !== t0) {
23
- ({
24
- icon: Icon,
25
- "aria-label": ariaLabel,
26
- description,
27
- disabled,
28
- tooltipDirection,
29
- unsafeDisableTooltip: t1,
30
- keyshortcuts,
31
- keybindingHint,
32
- className,
33
- ...props
34
- } = t0);
35
- $[0] = t0;
36
- $[1] = Icon;
37
- $[2] = ariaLabel;
38
- $[3] = className;
39
- $[4] = description;
40
- $[5] = disabled;
41
- $[6] = keybindingHint;
42
- $[7] = keyshortcuts;
43
- $[8] = props;
44
- $[9] = t1;
45
- $[10] = tooltipDirection;
46
- } else {
47
- Icon = $[1];
48
- ariaLabel = $[2];
49
- className = $[3];
50
- description = $[4];
51
- disabled = $[5];
52
- keybindingHint = $[6];
53
- keyshortcuts = $[7];
54
- props = $[8];
55
- t1 = $[9];
56
- tooltipDirection = $[10];
57
- }
58
- const unsafeDisableTooltip = t1 === undefined ? false : t1;
9
+ const IconButton = /*#__PURE__*/forwardRef(({
10
+ icon: Icon,
11
+ 'aria-label': ariaLabel,
12
+ description,
13
+ disabled,
14
+ tooltipDirection,
15
+ // This is planned to be a temporary prop until the default tooltip on icon buttons are fully rolled out.
16
+ unsafeDisableTooltip = false,
17
+ keyshortcuts,
18
+ keybindingHint,
19
+ className,
20
+ ...props
21
+ }, forwardedRef) => {
22
+ // If the icon button is already wrapped in a tooltip, do not add one.
59
23
  const {
60
24
  tooltipId
61
- } = React.useContext(TooltipContext);
25
+ } = React.useContext(TooltipContext); // Tooltip v2
62
26
  const {
63
27
  tooltipId: tooltipIdV1
64
- } = React.useContext(TooltipContext$1);
28
+ } = React.useContext(TooltipContext$1); // Tooltip v1
29
+
65
30
  const {
66
- "aria-expanded": isExpanded,
67
- "aria-haspopup": hasPopup
31
+ 'aria-expanded': isExpanded,
32
+ 'aria-haspopup': hasPopup
68
33
  } = props;
69
34
  const hasExternalTooltip = tooltipId || tooltipIdV1;
70
- const hasActivePopup = (isExpanded === true || isExpanded === "true") && hasPopup === "true";
71
- const withoutTooltip = unsafeDisableTooltip || disabled || ariaLabel === undefined || ariaLabel === "" || hasExternalTooltip;
35
+
36
+ // If the button has an active "popup" (like a menu), we don't want to show the tooltip.
37
+ // This is mostly for `ActionMenu`, but could be applicable elsewhere.
38
+ const hasActivePopup = (isExpanded === true || isExpanded === 'true') && hasPopup === 'true';
39
+ const withoutTooltip = unsafeDisableTooltip || disabled || ariaLabel === undefined || ariaLabel === '' || hasExternalTooltip;
72
40
  if (withoutTooltip) {
73
- let t2;
74
- if ($[11] !== className) {
75
- t2 = clsx(className, classes.IconButton);
76
- $[11] = className;
77
- $[12] = t2;
78
- } else {
79
- t2 = $[12];
80
- }
81
- let t3;
82
- if ($[13] !== Icon || $[14] !== ariaLabel || $[15] !== disabled || $[16] !== forwardedRef || $[17] !== props || $[18] !== t2) {
83
- t3 = /*#__PURE__*/jsx(ButtonBase, {
84
- icon: Icon,
85
- className: t2,
86
- "data-component": "IconButton",
87
- type: "button",
88
- "aria-label": ariaLabel,
89
- disabled: disabled,
90
- ...props,
91
- ref: forwardedRef
92
- });
93
- $[13] = Icon;
94
- $[14] = ariaLabel;
95
- $[15] = disabled;
96
- $[16] = forwardedRef;
97
- $[17] = props;
98
- $[18] = t2;
99
- $[19] = t3;
100
- } else {
101
- t3 = $[19];
102
- }
103
- return t3;
41
+ return /*#__PURE__*/jsx(ButtonBase, {
42
+ icon: Icon,
43
+ className: clsx(className, classes.IconButton),
44
+ "data-component": "IconButton",
45
+ type: "button",
46
+ "aria-label": ariaLabel,
47
+ disabled: disabled,
48
+ ...props,
49
+ // @ts-expect-error StyledButton wants both Anchor and Button refs
50
+ ref: forwardedRef
51
+ });
104
52
  } else {
105
- var _description, _keybindingHint, _keyshortcuts;
106
- const tooltipText = (_description = description) !== null && _description !== void 0 ? _description : ariaLabel;
107
- const t2 = description ? undefined : "label";
108
- const t3 = (_keybindingHint = keybindingHint) !== null && _keybindingHint !== void 0 ? _keybindingHint : keyshortcuts;
109
- let t4;
110
- if ($[20] !== className) {
111
- t4 = clsx(className, classes.IconButton);
112
- $[20] = className;
113
- $[21] = t4;
114
- } else {
115
- t4 = $[21];
116
- }
117
- const t5 = (_keyshortcuts = keyshortcuts) !== null && _keyshortcuts !== void 0 ? _keyshortcuts : undefined;
118
- const t6 = description ? ariaLabel : undefined;
119
- let t7;
120
- if ($[22] !== Icon || $[23] !== props || $[24] !== t4 || $[25] !== t5 || $[26] !== t6) {
121
- t7 = /*#__PURE__*/jsx(ButtonBase, {
53
+ const tooltipText = description !== null && description !== void 0 ? description : ariaLabel;
54
+ return /*#__PURE__*/jsx(Tooltip, {
55
+ ref: forwardedRef,
56
+ text: tooltipText,
57
+ type: description ? undefined : 'label',
58
+ direction: tooltipDirection,
59
+ keybindingHint: keybindingHint !== null && keybindingHint !== void 0 ? keybindingHint : keyshortcuts,
60
+ _privateDisableTooltip: hasActivePopup,
61
+ children: /*#__PURE__*/jsx(ButtonBase, {
122
62
  icon: Icon,
123
- className: t4,
63
+ className: clsx(className, classes.IconButton),
124
64
  "data-component": "IconButton",
125
65
  type: "button",
126
- "aria-keyshortcuts": t5,
127
- "aria-label": t6,
66
+ "aria-keyshortcuts": keyshortcuts !== null && keyshortcuts !== void 0 ? keyshortcuts : undefined
67
+ // If description is provided, we will use the tooltip to describe the button, so we need to keep the aria-label to label the button.
68
+ ,
69
+ "aria-label": description ? ariaLabel : undefined,
128
70
  ...props
129
- });
130
- $[22] = Icon;
131
- $[23] = props;
132
- $[24] = t4;
133
- $[25] = t5;
134
- $[26] = t6;
135
- $[27] = t7;
136
- } else {
137
- t7 = $[27];
138
- }
139
- let t8;
140
- if ($[28] !== forwardedRef || $[29] !== hasActivePopup || $[30] !== t2 || $[31] !== t3 || $[32] !== t7 || $[33] !== tooltipDirection || $[34] !== tooltipText) {
141
- t8 = /*#__PURE__*/jsx(Tooltip, {
142
- ref: forwardedRef,
143
- text: tooltipText,
144
- type: t2,
145
- direction: tooltipDirection,
146
- keybindingHint: t3,
147
- _privateDisableTooltip: hasActivePopup,
148
- children: t7
149
- });
150
- $[28] = forwardedRef;
151
- $[29] = hasActivePopup;
152
- $[30] = t2;
153
- $[31] = t3;
154
- $[32] = t7;
155
- $[33] = tooltipDirection;
156
- $[34] = tooltipText;
157
- $[35] = t8;
158
- } else {
159
- t8 = $[35];
160
- }
161
- return t8;
71
+ })
72
+ });
162
73
  }
163
74
  });
164
75
 
@@ -1,46 +1,18 @@
1
- import { c } from 'react-compiler-runtime';
2
1
  import { forwardRef } from 'react';
3
2
  import { ButtonBase } from './ButtonBase.js';
4
3
  import { jsx } from 'react/jsx-runtime';
5
4
 
6
- const LinkButton = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
7
- const $ = c(9);
8
- let children;
9
- let props;
10
- let t1;
11
- if ($[0] !== t0) {
12
- ({
13
- children,
14
- as: t1,
15
- ...props
16
- } = t0);
17
- $[0] = t0;
18
- $[1] = children;
19
- $[2] = props;
20
- $[3] = t1;
21
- } else {
22
- children = $[1];
23
- props = $[2];
24
- t1 = $[3];
25
- }
26
- const Component = t1 === undefined ? "a" : t1;
27
- let t2;
28
- if ($[4] !== Component || $[5] !== children || $[6] !== forwardedRef || $[7] !== props) {
29
- t2 = /*#__PURE__*/jsx(ButtonBase, {
30
- as: Component,
31
- ref: forwardedRef,
32
- ...props,
33
- children: children
34
- });
35
- $[4] = Component;
36
- $[5] = children;
37
- $[6] = forwardedRef;
38
- $[7] = props;
39
- $[8] = t2;
40
- } else {
41
- t2 = $[8];
42
- }
43
- return t2;
5
+ const LinkButton = /*#__PURE__*/forwardRef(({
6
+ children,
7
+ as: Component = 'a',
8
+ ...props
9
+ }, forwardedRef) => {
10
+ return /*#__PURE__*/jsx(ButtonBase, {
11
+ as: Component,
12
+ ref: forwardedRef,
13
+ ...props,
14
+ children: children
15
+ });
44
16
  });
45
17
 
46
18
  export { LinkButton };
@@ -1,4 +1,3 @@
1
- import { c } from 'react-compiler-runtime';
2
1
  import { clsx } from 'clsx';
3
2
  import React, { useContext, useEffect } from 'react';
4
3
  import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
@@ -11,170 +10,63 @@ import { useProvidedRefOrCreate } from '../hooks/useProvidedRefOrCreate.js';
11
10
  /**
12
11
  * An accessible, native checkbox component
13
12
  */
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
- }
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
+ ) => {
62
27
  const checkboxRef = useProvidedRefOrCreate(ref);
63
28
  const checkboxGroupContext = useContext(CheckboxGroupContext);
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;
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
+ });
178
70
  });
179
71
  Checkbox.displayName = 'Checkbox';
180
72
  Checkbox.__SLOT__ = Symbol('Checkbox');