@arc-ui/components 11.0.0 → 11.2.0
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/dist/Align/Align.esm.js +4 -4
- package/dist/Badge/Badge.cjs.d.ts +26 -0
- package/dist/Badge/Badge.cjs.js +37 -0
- package/dist/Badge/Badge.esm.d.ts +26 -0
- package/dist/Badge/Badge.esm.js +29 -0
- package/dist/Badge/package.json +7 -0
- package/dist/Base/Base.cjs.d.ts +1 -16
- package/dist/Base/Base.cjs.js +4 -16
- package/dist/Base/Base.esm.d.ts +1 -16
- package/dist/Base/Base.esm.js +3 -15
- package/dist/BrandLogo/BrandLogo.esm.d.ts +1 -1
- package/dist/BrandLogo/BrandLogo.esm.js +2 -2
- package/dist/Breadcrumbs/Breadcrumbs.esm.js +27 -27
- package/dist/Button/Button.esm.d.ts +1 -1
- package/dist/Button/Button.esm.js +4 -4
- package/dist/Card/Card.esm.js +27 -27
- package/dist/Checkbox/Checkbox.cjs.js +4 -1
- package/dist/Checkbox/Checkbox.esm.js +18 -15
- package/dist/Clock/Clock.esm.js +3 -3
- package/dist/Columns/Columns.esm.js +5 -5
- package/dist/Curve/Curve.esm.d.ts +1 -1
- package/dist/Curve/Curve.esm.js +1 -1
- package/dist/Disclosure/Disclosure.esm.d.ts +1 -1
- package/dist/Disclosure/Disclosure.esm.js +10 -10
- package/dist/Elevation/Elevation.esm.js +2 -2
- package/dist/FormControl/FormControl.cjs.d.ts +1 -1
- package/dist/FormControl/FormControl.cjs.js +4 -1
- package/dist/FormControl/FormControl.esm.d.ts +1 -1
- package/dist/FormControl/FormControl.esm.js +5 -2
- package/dist/Group/Group.esm.js +6 -6
- package/dist/Heading/Heading.esm.d.ts +1 -1
- package/dist/Heading/Heading.esm.js +2 -2
- package/dist/Icon/Icon.esm.d.ts +1 -1
- package/dist/Icon/Icon.esm.js +2 -2
- package/dist/Image/Image.esm.d.ts +1 -1
- package/dist/Image/Image.esm.js +1 -1
- package/dist/Markup/Markup.esm.js +3 -3
- package/dist/Poster/Poster.esm.d.ts +1 -1
- package/dist/Poster/Poster.esm.js +9 -9
- package/dist/RadioGroup/RadioGroup.cjs.d.ts +1 -1
- package/dist/RadioGroup/RadioGroup.cjs.js +4 -1
- package/dist/RadioGroup/RadioGroup.esm.d.ts +1 -1
- package/dist/RadioGroup/RadioGroup.esm.js +15 -12
- package/dist/Rule/Rule.esm.js +3 -3
- package/dist/Section/Section.esm.d.ts +1 -1
- package/dist/Section/Section.esm.js +1 -1
- package/dist/Select/Select.cjs.d.ts +25 -0
- package/dist/Select/Select.cjs.js +2611 -0
- package/dist/Select/Select.esm.d.ts +25 -0
- package/dist/Select/Select.esm.js +2584 -0
- package/dist/Select/package.json +7 -0
- package/dist/SiteFooter/SiteFooter.esm.js +33 -33
- package/dist/SiteHeader/SiteHeader.esm.d.ts +1 -1
- package/dist/SiteHeader/SiteHeader.esm.js +98 -98
- package/dist/Surface/Surface.esm.d.ts +1 -1
- package/dist/Surface/Surface.esm.js +1 -1
- package/dist/Switch/Switch.cjs.d.ts +40 -0
- package/dist/Switch/Switch.cjs.js +210 -0
- package/dist/Switch/Switch.esm.d.ts +40 -0
- package/dist/Switch/Switch.esm.js +202 -0
- package/dist/Switch/package.json +7 -0
- package/dist/Text/Text.esm.d.ts +1 -1
- package/dist/Text/Text.esm.js +2 -2
- package/dist/TextInput/TextInput.cjs.d.ts +5 -1
- package/dist/TextInput/TextInput.cjs.js +25 -6
- package/dist/TextInput/TextInput.esm.d.ts +5 -1
- package/dist/TextInput/TextInput.esm.js +28 -9
- package/dist/Truncate/Truncate.cjs.d.ts +18 -0
- package/dist/Truncate/Truncate.cjs.js +17 -0
- package/dist/Truncate/Truncate.esm.d.ts +18 -0
- package/dist/Truncate/Truncate.esm.js +9 -0
- package/dist/Truncate/package.json +7 -0
- package/dist/UniversalHeader/UniversalHeader.esm.js +8 -8
- package/dist/VerticalSpace/VerticalSpace.cjs.d.ts +1 -18
- package/dist/VerticalSpace/VerticalSpace.cjs.js +5 -20
- package/dist/VerticalSpace/VerticalSpace.esm.d.ts +1 -18
- package/dist/VerticalSpace/VerticalSpace.esm.js +4 -19
- package/dist/VisuallyHidden/VisuallyHidden.cjs.d.ts +1 -12
- package/dist/VisuallyHidden/VisuallyHidden.cjs.js +3 -12
- package/dist/VisuallyHidden/VisuallyHidden.esm.d.ts +1 -12
- package/dist/VisuallyHidden/VisuallyHidden.esm.js +2 -11
- package/dist/_shared/cjs/Base-e2b846fe.d.ts +19 -0
- package/dist/_shared/cjs/Base-e2b846fe.js +22 -0
- package/dist/_shared/cjs/BtIconTickAlt2Px-b12ecc78.js +425 -0
- package/dist/_shared/cjs/{FormControl-a1b7421b.d.ts → FormControl-e6b7d7c5.d.ts} +51 -3
- package/dist/_shared/cjs/{FormControl-a1b7421b.js → FormControl-e6b7d7c5.js} +40 -8
- package/dist/_shared/cjs/VerticalSpace-65ad083c.d.ts +18 -0
- package/dist/_shared/cjs/VerticalSpace-65ad083c.js +25 -0
- package/dist/_shared/cjs/VisuallyHidden-e2c8b291.d.ts +12 -0
- package/dist/_shared/cjs/VisuallyHidden-e2c8b291.js +17 -0
- package/dist/_shared/cjs/index-c81c9401.d.ts +1 -1
- package/dist/_shared/esm/Base-c235dc45.d.ts +19 -0
- package/dist/_shared/esm/Base-c235dc45.js +15 -0
- package/dist/_shared/esm/{BrandLogo-ea3dd0e6.js → BrandLogo-4f13fe85.js} +4 -4
- package/dist/_shared/esm/{BtIconChevronDown2Px-4abd079b.js → BtIconChevronDown2Px-782876e2.js} +2 -2
- package/dist/_shared/esm/{BtIconChevronRight2Px-a5cc1d05.js → BtIconChevronRight2Px-b8e7b4ad.js} +3 -3
- package/dist/_shared/esm/{BtIconChevronRightMid-386cf272.js → BtIconChevronRightMid-d9b11761.js} +2 -2
- package/dist/_shared/esm/BtIconTickAlt2Px-2c4ec3be.js +408 -0
- package/dist/_shared/esm/{Button-5ff56a7b.js → Button-69439f8f.js} +15 -15
- package/dist/_shared/esm/{Curve-cfdca379.js → Curve-50697f7e.js} +2 -2
- package/dist/_shared/esm/{FormControl-feedc495.d.ts → FormControl-84c9ace6.d.ts} +51 -3
- package/dist/_shared/esm/FormControl-84c9ace6.js +138 -0
- package/dist/_shared/esm/{Heading-183be76c.js → Heading-eb1e42db.js} +4 -4
- package/dist/_shared/esm/{Icon-76d0d8c0.js → Icon-61f7237a.js} +5 -5
- package/dist/_shared/esm/{Image-7e4948f6.js → Image-c0f3d42f.js} +7 -7
- package/dist/_shared/esm/{Section-f1256c87.js → Section-7bc71e26.js} +2 -2
- package/dist/_shared/esm/{Surface-d515d212.js → Surface-bf201530.js} +3 -3
- package/dist/_shared/esm/{Text-d8988620.js → Text-6b958ad8.js} +3 -3
- package/dist/_shared/esm/VerticalSpace-6b4f5e50.d.ts +18 -0
- package/dist/_shared/esm/VerticalSpace-6b4f5e50.js +19 -0
- package/dist/_shared/esm/VisuallyHidden-b9eebf71.d.ts +12 -0
- package/dist/_shared/esm/VisuallyHidden-b9eebf71.js +11 -0
- package/dist/_shared/esm/index-c81c9401.d.ts +1 -1
- package/dist/index.es.js +34623 -529
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +34527 -411
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/components/Badge/Badge.d.ts +25 -0
- package/dist/types/components/Badge/index.d.ts +1 -0
- package/dist/types/components/FormControl/FormControl.d.ts +17 -0
- package/dist/types/components/FormControl/FormControlDisclosure/FormControlDisclosure.d.ts +28 -0
- package/dist/types/components/FormControl/FormControlDisclosure/index.d.ts +1 -0
- package/dist/types/components/Select/Select.d.ts +2 -1
- package/dist/types/components/Switch/Switch.d.ts +13 -8
- package/dist/types/components/TextInput/TextInput.d.ts +4 -0
- package/dist/types/components/Truncate/Truncate.d.ts +17 -0
- package/dist/types/components/Truncate/index.d.ts +1 -0
- package/dist/types/components/index.d.ts +4 -0
- package/dist/types/hooks/use-aria-describedby.d.ts +5 -1
- package/dist/types/styles.d.ts +4 -0
- package/package.json +4 -4
- package/dist/_shared/esm/FormControl-feedc495.js +0 -106
- /package/dist/_shared/esm/{BrandLogo-ea3dd0e6.d.ts → BrandLogo-4f13fe85.d.ts} +0 -0
- /package/dist/_shared/esm/{Button-5ff56a7b.d.ts → Button-69439f8f.d.ts} +0 -0
- /package/dist/_shared/esm/{Curve-cfdca379.d.ts → Curve-50697f7e.d.ts} +0 -0
- /package/dist/_shared/esm/{Heading-183be76c.d.ts → Heading-eb1e42db.d.ts} +0 -0
- /package/dist/_shared/esm/{Icon-76d0d8c0.d.ts → Icon-61f7237a.d.ts} +0 -0
- /package/dist/_shared/esm/{Image-7e4948f6.d.ts → Image-c0f3d42f.d.ts} +0 -0
- /package/dist/_shared/esm/{Section-f1256c87.d.ts → Section-7bc71e26.d.ts} +0 -0
- /package/dist/_shared/esm/{Surface-d515d212.d.ts → Surface-bf201530.d.ts} +0 -0
- /package/dist/_shared/esm/{Text-d8988620.d.ts → Text-6b958ad8.d.ts} +0 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var index = require('../_shared/cjs/index-45bfb67b.js');
|
|
7
|
+
var BtIconTickAlt2Px = require('../_shared/cjs/BtIconTickAlt2Px-b12ecc78.js');
|
|
8
|
+
var Icon = require('../_shared/cjs/Icon-719d13d4.js');
|
|
9
|
+
var Surface = require('../_shared/cjs/Surface-d6b8010e.js');
|
|
10
|
+
var FormControl = require('../_shared/cjs/FormControl-e6b7d7c5.js');
|
|
11
|
+
var VerticalSpace = require('../_shared/cjs/VerticalSpace-65ad083c.js');
|
|
12
|
+
var Text = require('../_shared/cjs/Text-1d3844be.js');
|
|
13
|
+
require('react-dom');
|
|
14
|
+
require('../_shared/cjs/index-78b35bc1.js');
|
|
15
|
+
require('../_shared/cjs/suffix-modifier-edf7851e.js');
|
|
16
|
+
require('../_shared/cjs/BtIconChevronRightMid-5a38d855.js');
|
|
17
|
+
|
|
18
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
21
|
+
|
|
22
|
+
function $db6c3485150b8e66$export$1ab7ae714698c4b8(element) {
|
|
23
|
+
const [size, setSize] = React.useState(undefined);
|
|
24
|
+
BtIconTickAlt2Px.$9f79659886946c16$export$e5c5a5f917a5871c(()=>{
|
|
25
|
+
if (element) {
|
|
26
|
+
// provide size as early as possible
|
|
27
|
+
setSize({
|
|
28
|
+
width: element.offsetWidth,
|
|
29
|
+
height: element.offsetHeight
|
|
30
|
+
});
|
|
31
|
+
const resizeObserver = new ResizeObserver((entries)=>{
|
|
32
|
+
if (!Array.isArray(entries)) return;
|
|
33
|
+
// Since we only observe the one element, we don't need to loop over the
|
|
34
|
+
// array
|
|
35
|
+
if (!entries.length) return;
|
|
36
|
+
const entry = entries[0];
|
|
37
|
+
let width;
|
|
38
|
+
let height;
|
|
39
|
+
if ('borderBoxSize' in entry) {
|
|
40
|
+
const borderSizeEntry = entry['borderBoxSize']; // iron out differences between browsers
|
|
41
|
+
const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
|
|
42
|
+
width = borderSize['inlineSize'];
|
|
43
|
+
height = borderSize['blockSize'];
|
|
44
|
+
} else {
|
|
45
|
+
// for browsers that don't support `borderBoxSize`
|
|
46
|
+
// we calculate it ourselves to get the correct border box.
|
|
47
|
+
width = element.offsetWidth;
|
|
48
|
+
height = element.offsetHeight;
|
|
49
|
+
}
|
|
50
|
+
setSize({
|
|
51
|
+
width: width,
|
|
52
|
+
height: height
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
resizeObserver.observe(element, {
|
|
56
|
+
box: 'border-box'
|
|
57
|
+
});
|
|
58
|
+
return ()=>resizeObserver.unobserve(element)
|
|
59
|
+
;
|
|
60
|
+
} else // We only want to reset to `undefined` when the element becomes `null`,
|
|
61
|
+
// not if it changes to another element.
|
|
62
|
+
setSize(undefined);
|
|
63
|
+
}, [
|
|
64
|
+
element
|
|
65
|
+
]);
|
|
66
|
+
return size;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* -------------------------------------------------------------------------------------------------
|
|
70
|
+
* Switch
|
|
71
|
+
* -----------------------------------------------------------------------------------------------*/ const $6be4966fd9bbc698$var$SWITCH_NAME = 'Switch';
|
|
72
|
+
const [$6be4966fd9bbc698$var$createSwitchContext, $6be4966fd9bbc698$export$cf7f5f17f69cbd43] = BtIconTickAlt2Px.$c512c27ab02ef895$export$50c7b4e9d9f19c1($6be4966fd9bbc698$var$SWITCH_NAME);
|
|
73
|
+
const [$6be4966fd9bbc698$var$SwitchProvider, $6be4966fd9bbc698$var$useSwitchContext] = $6be4966fd9bbc698$var$createSwitchContext($6be4966fd9bbc698$var$SWITCH_NAME);
|
|
74
|
+
const $6be4966fd9bbc698$export$b5d5cf8927ab7262 = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
|
|
75
|
+
const { __scopeSwitch: __scopeSwitch , name: name , checked: checkedProp , defaultChecked: defaultChecked , required: required , disabled: disabled , value: value = 'on' , onCheckedChange: onCheckedChange , ...switchProps } = props;
|
|
76
|
+
const [button, setButton] = React.useState(null);
|
|
77
|
+
const composedRefs = BtIconTickAlt2Px.$6ed0406888f73fc4$export$c7b2cbe3552a0d05(forwardedRef, (node)=>setButton(node)
|
|
78
|
+
);
|
|
79
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false); // We set this to true by default so that events bubble to forms without JS (SSR)
|
|
80
|
+
const isFormControl = button ? Boolean(button.closest('form')) : true;
|
|
81
|
+
const [checked = false, setChecked] = BtIconTickAlt2Px.$71cd76cc60e0454e$export$6f32135080cb4c3({
|
|
82
|
+
prop: checkedProp,
|
|
83
|
+
defaultProp: defaultChecked,
|
|
84
|
+
onChange: onCheckedChange
|
|
85
|
+
});
|
|
86
|
+
return /*#__PURE__*/ React.createElement($6be4966fd9bbc698$var$SwitchProvider, {
|
|
87
|
+
scope: __scopeSwitch,
|
|
88
|
+
checked: checked,
|
|
89
|
+
disabled: disabled
|
|
90
|
+
}, /*#__PURE__*/ React.createElement(BtIconTickAlt2Px.$8927f6f2acc4f386$export$250ffa63cdc0d034.button, BtIconTickAlt2Px._extends({
|
|
91
|
+
type: "button",
|
|
92
|
+
role: "switch",
|
|
93
|
+
"aria-checked": checked,
|
|
94
|
+
"aria-required": required,
|
|
95
|
+
"data-state": $6be4966fd9bbc698$var$getState(checked),
|
|
96
|
+
"data-disabled": disabled ? '' : undefined,
|
|
97
|
+
disabled: disabled,
|
|
98
|
+
value: value
|
|
99
|
+
}, switchProps, {
|
|
100
|
+
ref: composedRefs,
|
|
101
|
+
onClick: BtIconTickAlt2Px.$e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onClick, (event)=>{
|
|
102
|
+
setChecked((prevChecked)=>!prevChecked
|
|
103
|
+
);
|
|
104
|
+
if (isFormControl) {
|
|
105
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(); // if switch is in a form, stop propagation from the button so that we only propagate
|
|
106
|
+
// one click event (from the input). We propagate changes from an input so that native
|
|
107
|
+
// form validation works and form events reflect switch updates.
|
|
108
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
})), isFormControl && /*#__PURE__*/ React.createElement($6be4966fd9bbc698$var$BubbleInput, {
|
|
112
|
+
control: button,
|
|
113
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
114
|
+
name: name,
|
|
115
|
+
value: value,
|
|
116
|
+
checked: checked,
|
|
117
|
+
required: required,
|
|
118
|
+
disabled: disabled // We transform because the input is absolutely positioned but we have
|
|
119
|
+
,
|
|
120
|
+
style: {
|
|
121
|
+
transform: 'translateX(-100%)'
|
|
122
|
+
}
|
|
123
|
+
}));
|
|
124
|
+
});
|
|
125
|
+
/* -------------------------------------------------------------------------------------------------
|
|
126
|
+
* SwitchThumb
|
|
127
|
+
* -----------------------------------------------------------------------------------------------*/ const $6be4966fd9bbc698$var$THUMB_NAME = 'SwitchThumb';
|
|
128
|
+
const $6be4966fd9bbc698$export$4d07bf653ea69106 = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
|
|
129
|
+
const { __scopeSwitch: __scopeSwitch , ...thumbProps } = props;
|
|
130
|
+
const context = $6be4966fd9bbc698$var$useSwitchContext($6be4966fd9bbc698$var$THUMB_NAME, __scopeSwitch);
|
|
131
|
+
return /*#__PURE__*/ React.createElement(BtIconTickAlt2Px.$8927f6f2acc4f386$export$250ffa63cdc0d034.span, BtIconTickAlt2Px._extends({
|
|
132
|
+
"data-state": $6be4966fd9bbc698$var$getState(context.checked),
|
|
133
|
+
"data-disabled": context.disabled ? '' : undefined
|
|
134
|
+
}, thumbProps, {
|
|
135
|
+
ref: forwardedRef
|
|
136
|
+
}));
|
|
137
|
+
});
|
|
138
|
+
/* ---------------------------------------------------------------------------------------------- */ const $6be4966fd9bbc698$var$BubbleInput = (props)=>{
|
|
139
|
+
const { control: control , checked: checked , bubbles: bubbles = true , ...inputProps } = props;
|
|
140
|
+
const ref = React.useRef(null);
|
|
141
|
+
const prevChecked = BtIconTickAlt2Px.$010c2913dbd2fe3d$export$5cae361ad82dce8b(checked);
|
|
142
|
+
const controlSize = $db6c3485150b8e66$export$1ab7ae714698c4b8(control); // Bubble checked change to parents (e.g form change event)
|
|
143
|
+
React.useEffect(()=>{
|
|
144
|
+
const input = ref.current;
|
|
145
|
+
const inputProto = window.HTMLInputElement.prototype;
|
|
146
|
+
const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked');
|
|
147
|
+
const setChecked = descriptor.set;
|
|
148
|
+
if (prevChecked !== checked && setChecked) {
|
|
149
|
+
const event = new Event('click', {
|
|
150
|
+
bubbles: bubbles
|
|
151
|
+
});
|
|
152
|
+
setChecked.call(input, checked);
|
|
153
|
+
input.dispatchEvent(event);
|
|
154
|
+
}
|
|
155
|
+
}, [
|
|
156
|
+
prevChecked,
|
|
157
|
+
checked,
|
|
158
|
+
bubbles
|
|
159
|
+
]);
|
|
160
|
+
return /*#__PURE__*/ React.createElement("input", BtIconTickAlt2Px._extends({
|
|
161
|
+
type: "checkbox",
|
|
162
|
+
"aria-hidden": true,
|
|
163
|
+
defaultChecked: checked
|
|
164
|
+
}, inputProps, {
|
|
165
|
+
tabIndex: -1,
|
|
166
|
+
ref: ref,
|
|
167
|
+
style: {
|
|
168
|
+
...props.style,
|
|
169
|
+
...controlSize,
|
|
170
|
+
position: 'absolute',
|
|
171
|
+
pointerEvents: 'none',
|
|
172
|
+
opacity: 0,
|
|
173
|
+
margin: 0
|
|
174
|
+
}
|
|
175
|
+
}));
|
|
176
|
+
};
|
|
177
|
+
function $6be4966fd9bbc698$var$getState(checked) {
|
|
178
|
+
return checked ? 'checked' : 'unchecked';
|
|
179
|
+
}
|
|
180
|
+
const $6be4966fd9bbc698$export$be92b6f5f03c0fe9 = $6be4966fd9bbc698$export$b5d5cf8927ab7262;
|
|
181
|
+
const $6be4966fd9bbc698$export$6521433ed15a34db = $6be4966fd9bbc698$export$4d07bf653ea69106;
|
|
182
|
+
|
|
183
|
+
/** Use `Switch` to toggle between checked and not checked. */
|
|
184
|
+
var Switch = function (_a) {
|
|
185
|
+
var defaultChecked = _a.defaultChecked, onCheckedChange = _a.onCheckedChange, label = _a.label, name = _a.name, onBlur = _a.onBlur, value = _a.value, _b = _a.isDisabled, isDisabled = _b === void 0 ? false : _b, errorMessage = _a.errorMessage, id = _a.id, _c = _a.labelSize, labelSize = _c === void 0 ? "s" : _c, statusText = _a.statusText, _d = _a.hideLabel, hideLabel = _d === void 0 ? false : _d;
|
|
186
|
+
var surface = React.useContext(Surface.Context).surface;
|
|
187
|
+
return (React__default["default"].createElement(FormControl.FormControl, { errorMessage: errorMessage, htmlFor: id, isDisabled: isDisabled, label: hideLabel ? "" : label, labelSize: labelSize, requirementStatus: "not-applicable" },
|
|
188
|
+
!hideLabel && React__default["default"].createElement(VerticalSpace.VerticalSpace, { size: "8" }),
|
|
189
|
+
React__default["default"].createElement("div", { className: "arc-Switch-container" },
|
|
190
|
+
React__default["default"].createElement($6be4966fd9bbc698$export$be92b6f5f03c0fe9, { id: id, "aria-label": label, defaultChecked: defaultChecked, name: name, value: value, onBlur: onBlur, onCheckedChange: onCheckedChange, disabled: isDisabled, className: index.classNames("arc-Switch", {
|
|
191
|
+
"arc-Switch--large": labelSize === "l",
|
|
192
|
+
"arc-Switch--isDisabled": isDisabled,
|
|
193
|
+
"arc-Switch--onDarkSurface": surface === "dark"
|
|
194
|
+
}) },
|
|
195
|
+
React__default["default"].createElement("div", { className: "arc-Switch-wrapper" },
|
|
196
|
+
React__default["default"].createElement($6be4966fd9bbc698$export$6521433ed15a34db, { className: "arc-Switch-thumb" },
|
|
197
|
+
React__default["default"].createElement("div", { className: "arc-Switch-thumbIcon" },
|
|
198
|
+
React__default["default"].createElement("div", { className: "arc-Switch-icon", "data-testid": "arc-switch-thumb-icon" },
|
|
199
|
+
React__default["default"].createElement(Icon.Icon, { icon: BtIconTickAlt2Px.BtIconTickAlt2Px_2, color: surface === "dark" ? "brand" : "brand", size: labelSize === "l" ? 24 : 16 })))))),
|
|
200
|
+
React__default["default"].createElement("div", { className: index.classNames("arc-Switch-statusText", {
|
|
201
|
+
"arc-Switch-statusText--isDisabled": isDisabled,
|
|
202
|
+
"arc-Switch-statusText--onDarkSurface": surface === "dark"
|
|
203
|
+
}) },
|
|
204
|
+
React__default["default"].createElement(Text.Text, { size: labelSize },
|
|
205
|
+
" ",
|
|
206
|
+
statusText,
|
|
207
|
+
" ")))));
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
exports.Switch = Switch;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { SwitchProps as RadixSwitchProps } from "@radix-ui/react-switch";
|
|
3
|
+
import { FormControlProps } from "../_shared/esm/FormControl-84c9ace6";
|
|
4
|
+
/** Use `Switch` to toggle between checked and not checked. */
|
|
5
|
+
declare const Switch: FC<SwitchProps>;
|
|
6
|
+
interface SwitchProps extends Omit<FormControlProps, "children" | "elementType" | "htmlFor" | "requirementStatus" | "disclosureText" | "disclosureTitle" | "onClickDisclosure" | "helper"> {
|
|
7
|
+
/**
|
|
8
|
+
* Hide Label above toggle?
|
|
9
|
+
*/
|
|
10
|
+
hideLabel?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Text to display next to `Switch`
|
|
13
|
+
*/
|
|
14
|
+
statusText?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Should the `Switch` be disabled?
|
|
17
|
+
*/
|
|
18
|
+
isDisabled?: FormControlProps["isDisabled"];
|
|
19
|
+
/**
|
|
20
|
+
* handler for blur
|
|
21
|
+
*/
|
|
22
|
+
onBlur?: RadixSwitchProps["onBlur"];
|
|
23
|
+
/**
|
|
24
|
+
* set the switch to be checked by default
|
|
25
|
+
*/
|
|
26
|
+
defaultChecked?: RadixSwitchProps["defaultChecked"];
|
|
27
|
+
/**
|
|
28
|
+
* value for the switch, is applied to a hidden checkbox if within a form
|
|
29
|
+
*/
|
|
30
|
+
value?: RadixSwitchProps["value"];
|
|
31
|
+
/**
|
|
32
|
+
* name for the hidden checkbox if within a form
|
|
33
|
+
*/
|
|
34
|
+
name?: RadixSwitchProps["name"];
|
|
35
|
+
/**
|
|
36
|
+
* callback for when the switch is toggled
|
|
37
|
+
*/
|
|
38
|
+
onCheckedChange?: RadixSwitchProps["onCheckedChange"];
|
|
39
|
+
}
|
|
40
|
+
export { Switch };
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import React__default, { useState, forwardRef, useRef, createElement, useEffect, useContext } from 'react';
|
|
2
|
+
import { c as classNames } from '../_shared/esm/index-2ae58626.js';
|
|
3
|
+
import { g as $9f79659886946c16$export$e5c5a5f917a5871c, $ as $c512c27ab02ef895$export$50c7b4e9d9f19c1, a as $6ed0406888f73fc4$export$c7b2cbe3552a0d05, h as $71cd76cc60e0454e$export$6f32135080cb4c3, d as $8927f6f2acc4f386$export$250ffa63cdc0d034, _ as _extends, e as $e42e1063c40fb3ef$export$b9ecd428b558ff10, i as $010c2913dbd2fe3d$export$5cae361ad82dce8b, B as BtIconTickAlt2Px_2 } from '../_shared/esm/BtIconTickAlt2Px-2c4ec3be.js';
|
|
4
|
+
import { I as Icon } from '../_shared/esm/Icon-61f7237a.js';
|
|
5
|
+
import { C as Context } from '../_shared/esm/Surface-bf201530.js';
|
|
6
|
+
import { F as FormControl } from '../_shared/esm/FormControl-84c9ace6.js';
|
|
7
|
+
import { V as VerticalSpace } from '../_shared/esm/VerticalSpace-6b4f5e50.js';
|
|
8
|
+
import { T as Text } from '../_shared/esm/Text-6b958ad8.js';
|
|
9
|
+
import 'react-dom';
|
|
10
|
+
import '../_shared/esm/index-229fc864.js';
|
|
11
|
+
import '../_shared/esm/suffix-modifier-f5e28822.js';
|
|
12
|
+
import '../_shared/esm/BtIconChevronRightMid-d9b11761.js';
|
|
13
|
+
|
|
14
|
+
function $db6c3485150b8e66$export$1ab7ae714698c4b8(element) {
|
|
15
|
+
const [size, setSize] = useState(undefined);
|
|
16
|
+
$9f79659886946c16$export$e5c5a5f917a5871c(()=>{
|
|
17
|
+
if (element) {
|
|
18
|
+
// provide size as early as possible
|
|
19
|
+
setSize({
|
|
20
|
+
width: element.offsetWidth,
|
|
21
|
+
height: element.offsetHeight
|
|
22
|
+
});
|
|
23
|
+
const resizeObserver = new ResizeObserver((entries)=>{
|
|
24
|
+
if (!Array.isArray(entries)) return;
|
|
25
|
+
// Since we only observe the one element, we don't need to loop over the
|
|
26
|
+
// array
|
|
27
|
+
if (!entries.length) return;
|
|
28
|
+
const entry = entries[0];
|
|
29
|
+
let width;
|
|
30
|
+
let height;
|
|
31
|
+
if ('borderBoxSize' in entry) {
|
|
32
|
+
const borderSizeEntry = entry['borderBoxSize']; // iron out differences between browsers
|
|
33
|
+
const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
|
|
34
|
+
width = borderSize['inlineSize'];
|
|
35
|
+
height = borderSize['blockSize'];
|
|
36
|
+
} else {
|
|
37
|
+
// for browsers that don't support `borderBoxSize`
|
|
38
|
+
// we calculate it ourselves to get the correct border box.
|
|
39
|
+
width = element.offsetWidth;
|
|
40
|
+
height = element.offsetHeight;
|
|
41
|
+
}
|
|
42
|
+
setSize({
|
|
43
|
+
width: width,
|
|
44
|
+
height: height
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
resizeObserver.observe(element, {
|
|
48
|
+
box: 'border-box'
|
|
49
|
+
});
|
|
50
|
+
return ()=>resizeObserver.unobserve(element)
|
|
51
|
+
;
|
|
52
|
+
} else // We only want to reset to `undefined` when the element becomes `null`,
|
|
53
|
+
// not if it changes to another element.
|
|
54
|
+
setSize(undefined);
|
|
55
|
+
}, [
|
|
56
|
+
element
|
|
57
|
+
]);
|
|
58
|
+
return size;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* -------------------------------------------------------------------------------------------------
|
|
62
|
+
* Switch
|
|
63
|
+
* -----------------------------------------------------------------------------------------------*/ const $6be4966fd9bbc698$var$SWITCH_NAME = 'Switch';
|
|
64
|
+
const [$6be4966fd9bbc698$var$createSwitchContext, $6be4966fd9bbc698$export$cf7f5f17f69cbd43] = $c512c27ab02ef895$export$50c7b4e9d9f19c1($6be4966fd9bbc698$var$SWITCH_NAME);
|
|
65
|
+
const [$6be4966fd9bbc698$var$SwitchProvider, $6be4966fd9bbc698$var$useSwitchContext] = $6be4966fd9bbc698$var$createSwitchContext($6be4966fd9bbc698$var$SWITCH_NAME);
|
|
66
|
+
const $6be4966fd9bbc698$export$b5d5cf8927ab7262 = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
|
|
67
|
+
const { __scopeSwitch: __scopeSwitch , name: name , checked: checkedProp , defaultChecked: defaultChecked , required: required , disabled: disabled , value: value = 'on' , onCheckedChange: onCheckedChange , ...switchProps } = props;
|
|
68
|
+
const [button, setButton] = useState(null);
|
|
69
|
+
const composedRefs = $6ed0406888f73fc4$export$c7b2cbe3552a0d05(forwardedRef, (node)=>setButton(node)
|
|
70
|
+
);
|
|
71
|
+
const hasConsumerStoppedPropagationRef = useRef(false); // We set this to true by default so that events bubble to forms without JS (SSR)
|
|
72
|
+
const isFormControl = button ? Boolean(button.closest('form')) : true;
|
|
73
|
+
const [checked = false, setChecked] = $71cd76cc60e0454e$export$6f32135080cb4c3({
|
|
74
|
+
prop: checkedProp,
|
|
75
|
+
defaultProp: defaultChecked,
|
|
76
|
+
onChange: onCheckedChange
|
|
77
|
+
});
|
|
78
|
+
return /*#__PURE__*/ createElement($6be4966fd9bbc698$var$SwitchProvider, {
|
|
79
|
+
scope: __scopeSwitch,
|
|
80
|
+
checked: checked,
|
|
81
|
+
disabled: disabled
|
|
82
|
+
}, /*#__PURE__*/ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.button, _extends({
|
|
83
|
+
type: "button",
|
|
84
|
+
role: "switch",
|
|
85
|
+
"aria-checked": checked,
|
|
86
|
+
"aria-required": required,
|
|
87
|
+
"data-state": $6be4966fd9bbc698$var$getState(checked),
|
|
88
|
+
"data-disabled": disabled ? '' : undefined,
|
|
89
|
+
disabled: disabled,
|
|
90
|
+
value: value
|
|
91
|
+
}, switchProps, {
|
|
92
|
+
ref: composedRefs,
|
|
93
|
+
onClick: $e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onClick, (event)=>{
|
|
94
|
+
setChecked((prevChecked)=>!prevChecked
|
|
95
|
+
);
|
|
96
|
+
if (isFormControl) {
|
|
97
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(); // if switch is in a form, stop propagation from the button so that we only propagate
|
|
98
|
+
// one click event (from the input). We propagate changes from an input so that native
|
|
99
|
+
// form validation works and form events reflect switch updates.
|
|
100
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
})), isFormControl && /*#__PURE__*/ createElement($6be4966fd9bbc698$var$BubbleInput, {
|
|
104
|
+
control: button,
|
|
105
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
106
|
+
name: name,
|
|
107
|
+
value: value,
|
|
108
|
+
checked: checked,
|
|
109
|
+
required: required,
|
|
110
|
+
disabled: disabled // We transform because the input is absolutely positioned but we have
|
|
111
|
+
,
|
|
112
|
+
style: {
|
|
113
|
+
transform: 'translateX(-100%)'
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
116
|
+
});
|
|
117
|
+
/* -------------------------------------------------------------------------------------------------
|
|
118
|
+
* SwitchThumb
|
|
119
|
+
* -----------------------------------------------------------------------------------------------*/ const $6be4966fd9bbc698$var$THUMB_NAME = 'SwitchThumb';
|
|
120
|
+
const $6be4966fd9bbc698$export$4d07bf653ea69106 = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
|
|
121
|
+
const { __scopeSwitch: __scopeSwitch , ...thumbProps } = props;
|
|
122
|
+
const context = $6be4966fd9bbc698$var$useSwitchContext($6be4966fd9bbc698$var$THUMB_NAME, __scopeSwitch);
|
|
123
|
+
return /*#__PURE__*/ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.span, _extends({
|
|
124
|
+
"data-state": $6be4966fd9bbc698$var$getState(context.checked),
|
|
125
|
+
"data-disabled": context.disabled ? '' : undefined
|
|
126
|
+
}, thumbProps, {
|
|
127
|
+
ref: forwardedRef
|
|
128
|
+
}));
|
|
129
|
+
});
|
|
130
|
+
/* ---------------------------------------------------------------------------------------------- */ const $6be4966fd9bbc698$var$BubbleInput = (props)=>{
|
|
131
|
+
const { control: control , checked: checked , bubbles: bubbles = true , ...inputProps } = props;
|
|
132
|
+
const ref = useRef(null);
|
|
133
|
+
const prevChecked = $010c2913dbd2fe3d$export$5cae361ad82dce8b(checked);
|
|
134
|
+
const controlSize = $db6c3485150b8e66$export$1ab7ae714698c4b8(control); // Bubble checked change to parents (e.g form change event)
|
|
135
|
+
useEffect(()=>{
|
|
136
|
+
const input = ref.current;
|
|
137
|
+
const inputProto = window.HTMLInputElement.prototype;
|
|
138
|
+
const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked');
|
|
139
|
+
const setChecked = descriptor.set;
|
|
140
|
+
if (prevChecked !== checked && setChecked) {
|
|
141
|
+
const event = new Event('click', {
|
|
142
|
+
bubbles: bubbles
|
|
143
|
+
});
|
|
144
|
+
setChecked.call(input, checked);
|
|
145
|
+
input.dispatchEvent(event);
|
|
146
|
+
}
|
|
147
|
+
}, [
|
|
148
|
+
prevChecked,
|
|
149
|
+
checked,
|
|
150
|
+
bubbles
|
|
151
|
+
]);
|
|
152
|
+
return /*#__PURE__*/ createElement("input", _extends({
|
|
153
|
+
type: "checkbox",
|
|
154
|
+
"aria-hidden": true,
|
|
155
|
+
defaultChecked: checked
|
|
156
|
+
}, inputProps, {
|
|
157
|
+
tabIndex: -1,
|
|
158
|
+
ref: ref,
|
|
159
|
+
style: {
|
|
160
|
+
...props.style,
|
|
161
|
+
...controlSize,
|
|
162
|
+
position: 'absolute',
|
|
163
|
+
pointerEvents: 'none',
|
|
164
|
+
opacity: 0,
|
|
165
|
+
margin: 0
|
|
166
|
+
}
|
|
167
|
+
}));
|
|
168
|
+
};
|
|
169
|
+
function $6be4966fd9bbc698$var$getState(checked) {
|
|
170
|
+
return checked ? 'checked' : 'unchecked';
|
|
171
|
+
}
|
|
172
|
+
const $6be4966fd9bbc698$export$be92b6f5f03c0fe9 = $6be4966fd9bbc698$export$b5d5cf8927ab7262;
|
|
173
|
+
const $6be4966fd9bbc698$export$6521433ed15a34db = $6be4966fd9bbc698$export$4d07bf653ea69106;
|
|
174
|
+
|
|
175
|
+
/** Use `Switch` to toggle between checked and not checked. */
|
|
176
|
+
var Switch = function (_a) {
|
|
177
|
+
var defaultChecked = _a.defaultChecked, onCheckedChange = _a.onCheckedChange, label = _a.label, name = _a.name, onBlur = _a.onBlur, value = _a.value, _b = _a.isDisabled, isDisabled = _b === void 0 ? false : _b, errorMessage = _a.errorMessage, id = _a.id, _c = _a.labelSize, labelSize = _c === void 0 ? "s" : _c, statusText = _a.statusText, _d = _a.hideLabel, hideLabel = _d === void 0 ? false : _d;
|
|
178
|
+
var surface = useContext(Context).surface;
|
|
179
|
+
return (React__default.createElement(FormControl, { errorMessage: errorMessage, htmlFor: id, isDisabled: isDisabled, label: hideLabel ? "" : label, labelSize: labelSize, requirementStatus: "not-applicable" },
|
|
180
|
+
!hideLabel && React__default.createElement(VerticalSpace, { size: "8" }),
|
|
181
|
+
React__default.createElement("div", { className: "arc-Switch-container" },
|
|
182
|
+
React__default.createElement($6be4966fd9bbc698$export$be92b6f5f03c0fe9, { id: id, "aria-label": label, defaultChecked: defaultChecked, name: name, value: value, onBlur: onBlur, onCheckedChange: onCheckedChange, disabled: isDisabled, className: classNames("arc-Switch", {
|
|
183
|
+
"arc-Switch--large": labelSize === "l",
|
|
184
|
+
"arc-Switch--isDisabled": isDisabled,
|
|
185
|
+
"arc-Switch--onDarkSurface": surface === "dark"
|
|
186
|
+
}) },
|
|
187
|
+
React__default.createElement("div", { className: "arc-Switch-wrapper" },
|
|
188
|
+
React__default.createElement($6be4966fd9bbc698$export$6521433ed15a34db, { className: "arc-Switch-thumb" },
|
|
189
|
+
React__default.createElement("div", { className: "arc-Switch-thumbIcon" },
|
|
190
|
+
React__default.createElement("div", { className: "arc-Switch-icon", "data-testid": "arc-switch-thumb-icon" },
|
|
191
|
+
React__default.createElement(Icon, { icon: BtIconTickAlt2Px_2, color: surface === "dark" ? "brand" : "brand", size: labelSize === "l" ? 24 : 16 })))))),
|
|
192
|
+
React__default.createElement("div", { className: classNames("arc-Switch-statusText", {
|
|
193
|
+
"arc-Switch-statusText--isDisabled": isDisabled,
|
|
194
|
+
"arc-Switch-statusText--onDarkSurface": surface === "dark"
|
|
195
|
+
}) },
|
|
196
|
+
React__default.createElement(Text, { size: labelSize },
|
|
197
|
+
" ",
|
|
198
|
+
statusText,
|
|
199
|
+
" ")))));
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
export { Switch };
|
package/dist/Text/Text.esm.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Text } from "../_shared/esm/Text-
|
|
1
|
+
export { Text } from "../_shared/esm/Text-6b958ad8";
|
package/dist/Text/Text.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { T as Text } from '../_shared/esm/Text-
|
|
1
|
+
export { T as Text } from '../_shared/esm/Text-6b958ad8.js';
|
|
2
2
|
import '../_shared/esm/index-229fc864.js';
|
|
3
3
|
import '../_shared/esm/index-2ae58626.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import '../_shared/esm/suffix-modifier-f5e28822.js';
|
|
6
|
-
import '../_shared/esm/Surface-
|
|
6
|
+
import '../_shared/esm/Surface-bf201530.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { FC } from "react";
|
|
4
|
-
import { FormControlProps } from "../_shared/cjs/FormControl-
|
|
4
|
+
import { FormControlProps } from "../_shared/cjs/FormControl-e6b7d7c5";
|
|
5
5
|
type EventType = React.ChangeEvent<HTMLInputElement>;
|
|
6
6
|
/**
|
|
7
7
|
* Use `TextInput` to allow custom user text entry with a keyboard.
|
|
@@ -58,6 +58,10 @@ interface TextInputProps extends Omit<FormControlProps, "children" | "elementTyp
|
|
|
58
58
|
* Validation regex pattern.
|
|
59
59
|
*/
|
|
60
60
|
pattern?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Enable button to toggle TextInput type from `Selected Type` to `Text`
|
|
63
|
+
*/
|
|
64
|
+
showPassword?: boolean;
|
|
61
65
|
/**
|
|
62
66
|
* Type for the input. `number` will be changed to `text` and set the `numeric` inputMode.
|
|
63
67
|
*/
|
|
@@ -5,8 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var index = require('../_shared/cjs/index-78b35bc1.js');
|
|
6
6
|
var index$1 = require('../_shared/cjs/index-45bfb67b.js');
|
|
7
7
|
var React = require('react');
|
|
8
|
-
var FormControl = require('../_shared/cjs/FormControl-
|
|
8
|
+
var FormControl = require('../_shared/cjs/FormControl-e6b7d7c5.js');
|
|
9
9
|
var Surface = require('../_shared/cjs/Surface-d6b8010e.js');
|
|
10
|
+
var VisuallyHidden = require('../_shared/cjs/VisuallyHidden-e2c8b291.js');
|
|
11
|
+
require('../_shared/cjs/Text-1d3844be.js');
|
|
12
|
+
require('../_shared/cjs/suffix-modifier-edf7851e.js');
|
|
13
|
+
require('../_shared/cjs/BtIconChevronRightMid-5a38d855.js');
|
|
10
14
|
|
|
11
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
16
|
|
|
@@ -43,22 +47,37 @@ var useNumericInput = function (props) {
|
|
|
43
47
|
* Use `TextInput` to allow custom user text entry with a keyboard.
|
|
44
48
|
*/
|
|
45
49
|
var TextInput = React.forwardRef(function (_a, ref) {
|
|
46
|
-
var _b = _a.defaultValue, defaultValue = _b === void 0 ? "" : _b, errorMessage = _a.errorMessage, helper = _a.helper, id = _a.id, inputMode = _a.inputMode, _c = _a.isDisabled, isDisabled = _c === void 0 ? false : _c, _d = _a.isReadOnly, isReadOnly = _d === void 0 ? false : _d, _e = _a.isRequired, isRequired = _e === void 0 ? false : _e, label = _a.label, _f = _a.labelSize, labelSize = _f === void 0 ? "l" : _f, maxLength = _a.maxLength, minLength = _a.minLength, name = _a.name, onBlur = _a.onBlur, onChange = _a.onChange, pattern = _a.pattern, _g = _a.type, type = _g === void 0 ? "text" : _g, value = _a.value, props = index.__rest(_a, ["defaultValue", "errorMessage", "helper", "id", "inputMode", "isDisabled", "isReadOnly", "isRequired", "label", "labelSize", "maxLength", "minLength", "name", "onBlur", "onChange", "pattern", "type", "value"]);
|
|
50
|
+
var _b = _a.defaultValue, defaultValue = _b === void 0 ? "" : _b, errorMessage = _a.errorMessage, helper = _a.helper, id = _a.id, inputMode = _a.inputMode, _c = _a.isDisabled, isDisabled = _c === void 0 ? false : _c, _d = _a.isReadOnly, isReadOnly = _d === void 0 ? false : _d, _e = _a.isRequired, isRequired = _e === void 0 ? false : _e, label = _a.label, _f = _a.labelSize, labelSize = _f === void 0 ? "l" : _f, maxLength = _a.maxLength, minLength = _a.minLength, name = _a.name, onBlur = _a.onBlur, onChange = _a.onChange, onClickDisclosure = _a.onClickDisclosure, pattern = _a.pattern, _g = _a.type, type = _g === void 0 ? "text" : _g, _h = _a.showPassword, showPassword = _h === void 0 ? false : _h, value = _a.value, disclosureTitle = _a.disclosureTitle, disclosureText = _a.disclosureText, props = index.__rest(_a, ["defaultValue", "errorMessage", "helper", "id", "inputMode", "isDisabled", "isReadOnly", "isRequired", "label", "labelSize", "maxLength", "minLength", "name", "onBlur", "onChange", "onClickDisclosure", "pattern", "type", "showPassword", "value", "disclosureTitle", "disclosureText"]);
|
|
47
51
|
var surface = React.useContext(Surface.Context).surface;
|
|
48
|
-
var
|
|
52
|
+
var _j = React.useState(false), showPasswordToggle = _j[0], setShowPasswordToggle = _j[1];
|
|
53
|
+
var inferredInputProps = useNumericInput({
|
|
54
|
+
inputMode: inputMode,
|
|
55
|
+
pattern: pattern,
|
|
56
|
+
type: showPasswordToggle ? "text" : type
|
|
57
|
+
});
|
|
49
58
|
// Although this is used within FormControlWrapper, it's deterministic so we can call it here too
|
|
50
59
|
var ariaDescribedby = FormControl.useAriaDescribedby({
|
|
51
60
|
errorMessage: errorMessage,
|
|
52
61
|
id: id,
|
|
53
|
-
helper: helper
|
|
62
|
+
helper: helper,
|
|
63
|
+
disclosureText: disclosureText
|
|
54
64
|
}).ariaDescribedby;
|
|
55
65
|
return (React__default["default"].createElement("div", index.__assign({ className: index$1.classNames({
|
|
56
66
|
"arc-TextInput": true,
|
|
67
|
+
"arc-TextInput--withPasswordToggle": showPassword,
|
|
57
68
|
"arc-TextInput--invalid": errorMessage,
|
|
58
69
|
"arc-TextInput--onDarkSurface": surface === "dark"
|
|
59
70
|
}) }, index.filterDataAttrs(props)),
|
|
60
|
-
React__default["default"].createElement(FormControl.FormControl, { errorMessage: errorMessage, helper: helper, htmlFor: id, label: label, labelSize: labelSize, requirementStatus: isRequired ? "required" : "optional" },
|
|
61
|
-
React__default["default"].createElement("
|
|
71
|
+
React__default["default"].createElement(FormControl.FormControl, { errorMessage: errorMessage, helper: helper, htmlFor: id, isDisabled: isDisabled, label: label, labelSize: labelSize, requirementStatus: isRequired ? "required" : "optional", disclosureTitle: disclosureTitle, disclosureText: disclosureText, onClickDisclosure: onClickDisclosure },
|
|
72
|
+
React__default["default"].createElement("div", { className: "arc-TextInput-inputWrapper" },
|
|
73
|
+
React__default["default"].createElement("input", index.__assign({ "aria-describedby": ariaDescribedby, "aria-invalid": errorMessage ? "true" : "false", className: "arc-TextInput-input", defaultValue: typeof value !== "undefined" ? undefined : defaultValue, disabled: isDisabled, id: id, maxLength: maxLength, minLength: minLength, name: name, onChange: onChange, onBlur: onBlur, readOnly: isReadOnly, ref: ref, required: isRequired, value: typeof value !== "undefined" ? value : undefined }, inferredInputProps)),
|
|
74
|
+
showPassword && (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
75
|
+
React__default["default"].createElement("button", { className: "arc-TextInput-passwordToggle", onClick: function () { return setShowPasswordToggle(function (p) { return !p; }); }, type: "button" }, showPasswordToggle ? "Hide" : "Show"),
|
|
76
|
+
React__default["default"].createElement(VisuallyHidden.VisuallyHidden, null,
|
|
77
|
+
React__default["default"].createElement("div", { "aria-live": "polite" },
|
|
78
|
+
React__default["default"].createElement("p", null, showPasswordToggle
|
|
79
|
+
? "Your password is shown"
|
|
80
|
+
: "Your password is hidden")))))))));
|
|
62
81
|
});
|
|
63
82
|
|
|
64
83
|
exports.TextInput = TextInput;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { FC } from "react";
|
|
4
|
-
import { FormControlProps } from "../_shared/esm/FormControl-
|
|
4
|
+
import { FormControlProps } from "../_shared/esm/FormControl-84c9ace6";
|
|
5
5
|
type EventType = React.ChangeEvent<HTMLInputElement>;
|
|
6
6
|
/**
|
|
7
7
|
* Use `TextInput` to allow custom user text entry with a keyboard.
|
|
@@ -58,6 +58,10 @@ interface TextInputProps extends Omit<FormControlProps, "children" | "elementTyp
|
|
|
58
58
|
* Validation regex pattern.
|
|
59
59
|
*/
|
|
60
60
|
pattern?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Enable button to toggle TextInput type from `Selected Type` to `Text`
|
|
63
|
+
*/
|
|
64
|
+
showPassword?: boolean;
|
|
61
65
|
/**
|
|
62
66
|
* Type for the input. `number` will be changed to `text` and set the `numeric` inputMode.
|
|
63
67
|
*/
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { _ as __rest, a as __assign, f as filterDataAttrs } from '../_shared/esm/index-229fc864.js';
|
|
2
2
|
import { c as classNames } from '../_shared/esm/index-2ae58626.js';
|
|
3
|
-
import
|
|
4
|
-
import { u as useAriaDescribedby, F as FormControl } from '../_shared/esm/FormControl-
|
|
5
|
-
import { C as Context } from '../_shared/esm/Surface-
|
|
3
|
+
import React__default, { forwardRef, useContext, useState } from 'react';
|
|
4
|
+
import { u as useAriaDescribedby, F as FormControl } from '../_shared/esm/FormControl-84c9ace6.js';
|
|
5
|
+
import { C as Context } from '../_shared/esm/Surface-bf201530.js';
|
|
6
|
+
import { V as VisuallyHidden } from '../_shared/esm/VisuallyHidden-b9eebf71.js';
|
|
7
|
+
import '../_shared/esm/Text-6b958ad8.js';
|
|
8
|
+
import '../_shared/esm/suffix-modifier-f5e28822.js';
|
|
9
|
+
import '../_shared/esm/BtIconChevronRightMid-d9b11761.js';
|
|
6
10
|
|
|
7
11
|
/**
|
|
8
12
|
* Infer the correct inputMode, pattern and type if specifying a `number` type.
|
|
@@ -35,22 +39,37 @@ var useNumericInput = function (props) {
|
|
|
35
39
|
* Use `TextInput` to allow custom user text entry with a keyboard.
|
|
36
40
|
*/
|
|
37
41
|
var TextInput = forwardRef(function (_a, ref) {
|
|
38
|
-
var _b = _a.defaultValue, defaultValue = _b === void 0 ? "" : _b, errorMessage = _a.errorMessage, helper = _a.helper, id = _a.id, inputMode = _a.inputMode, _c = _a.isDisabled, isDisabled = _c === void 0 ? false : _c, _d = _a.isReadOnly, isReadOnly = _d === void 0 ? false : _d, _e = _a.isRequired, isRequired = _e === void 0 ? false : _e, label = _a.label, _f = _a.labelSize, labelSize = _f === void 0 ? "l" : _f, maxLength = _a.maxLength, minLength = _a.minLength, name = _a.name, onBlur = _a.onBlur, onChange = _a.onChange, pattern = _a.pattern, _g = _a.type, type = _g === void 0 ? "text" : _g, value = _a.value, props = __rest(_a, ["defaultValue", "errorMessage", "helper", "id", "inputMode", "isDisabled", "isReadOnly", "isRequired", "label", "labelSize", "maxLength", "minLength", "name", "onBlur", "onChange", "pattern", "type", "value"]);
|
|
42
|
+
var _b = _a.defaultValue, defaultValue = _b === void 0 ? "" : _b, errorMessage = _a.errorMessage, helper = _a.helper, id = _a.id, inputMode = _a.inputMode, _c = _a.isDisabled, isDisabled = _c === void 0 ? false : _c, _d = _a.isReadOnly, isReadOnly = _d === void 0 ? false : _d, _e = _a.isRequired, isRequired = _e === void 0 ? false : _e, label = _a.label, _f = _a.labelSize, labelSize = _f === void 0 ? "l" : _f, maxLength = _a.maxLength, minLength = _a.minLength, name = _a.name, onBlur = _a.onBlur, onChange = _a.onChange, onClickDisclosure = _a.onClickDisclosure, pattern = _a.pattern, _g = _a.type, type = _g === void 0 ? "text" : _g, _h = _a.showPassword, showPassword = _h === void 0 ? false : _h, value = _a.value, disclosureTitle = _a.disclosureTitle, disclosureText = _a.disclosureText, props = __rest(_a, ["defaultValue", "errorMessage", "helper", "id", "inputMode", "isDisabled", "isReadOnly", "isRequired", "label", "labelSize", "maxLength", "minLength", "name", "onBlur", "onChange", "onClickDisclosure", "pattern", "type", "showPassword", "value", "disclosureTitle", "disclosureText"]);
|
|
39
43
|
var surface = useContext(Context).surface;
|
|
40
|
-
var
|
|
44
|
+
var _j = useState(false), showPasswordToggle = _j[0], setShowPasswordToggle = _j[1];
|
|
45
|
+
var inferredInputProps = useNumericInput({
|
|
46
|
+
inputMode: inputMode,
|
|
47
|
+
pattern: pattern,
|
|
48
|
+
type: showPasswordToggle ? "text" : type
|
|
49
|
+
});
|
|
41
50
|
// Although this is used within FormControlWrapper, it's deterministic so we can call it here too
|
|
42
51
|
var ariaDescribedby = useAriaDescribedby({
|
|
43
52
|
errorMessage: errorMessage,
|
|
44
53
|
id: id,
|
|
45
|
-
helper: helper
|
|
54
|
+
helper: helper,
|
|
55
|
+
disclosureText: disclosureText
|
|
46
56
|
}).ariaDescribedby;
|
|
47
|
-
return (
|
|
57
|
+
return (React__default.createElement("div", __assign({ className: classNames({
|
|
48
58
|
"arc-TextInput": true,
|
|
59
|
+
"arc-TextInput--withPasswordToggle": showPassword,
|
|
49
60
|
"arc-TextInput--invalid": errorMessage,
|
|
50
61
|
"arc-TextInput--onDarkSurface": surface === "dark"
|
|
51
62
|
}) }, filterDataAttrs(props)),
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
React__default.createElement(FormControl, { errorMessage: errorMessage, helper: helper, htmlFor: id, isDisabled: isDisabled, label: label, labelSize: labelSize, requirementStatus: isRequired ? "required" : "optional", disclosureTitle: disclosureTitle, disclosureText: disclosureText, onClickDisclosure: onClickDisclosure },
|
|
64
|
+
React__default.createElement("div", { className: "arc-TextInput-inputWrapper" },
|
|
65
|
+
React__default.createElement("input", __assign({ "aria-describedby": ariaDescribedby, "aria-invalid": errorMessage ? "true" : "false", className: "arc-TextInput-input", defaultValue: typeof value !== "undefined" ? undefined : defaultValue, disabled: isDisabled, id: id, maxLength: maxLength, minLength: minLength, name: name, onChange: onChange, onBlur: onBlur, readOnly: isReadOnly, ref: ref, required: isRequired, value: typeof value !== "undefined" ? value : undefined }, inferredInputProps)),
|
|
66
|
+
showPassword && (React__default.createElement(React__default.Fragment, null,
|
|
67
|
+
React__default.createElement("button", { className: "arc-TextInput-passwordToggle", onClick: function () { return setShowPasswordToggle(function (p) { return !p; }); }, type: "button" }, showPasswordToggle ? "Hide" : "Show"),
|
|
68
|
+
React__default.createElement(VisuallyHidden, null,
|
|
69
|
+
React__default.createElement("div", { "aria-live": "polite" },
|
|
70
|
+
React__default.createElement("p", null, showPasswordToggle
|
|
71
|
+
? "Your password is shown"
|
|
72
|
+
: "Your password is hidden")))))))));
|
|
54
73
|
});
|
|
55
74
|
|
|
56
75
|
export { TextInput };
|