@arc-ui/components 11.1.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/Select/Select.cjs.js +207 -606
- package/dist/Select/Select.esm.js +43 -442
- 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/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/_shared/cjs/BtIconTickAlt2Px-b12ecc78.js +425 -0
- package/dist/_shared/cjs/VerticalSpace-65ad083c.d.ts +18 -0
- package/dist/_shared/cjs/VerticalSpace-65ad083c.js +25 -0
- package/dist/_shared/esm/BtIconTickAlt2Px-2c4ec3be.js +408 -0
- package/dist/_shared/esm/VerticalSpace-6b4f5e50.d.ts +18 -0
- package/dist/_shared/esm/VerticalSpace-6b4f5e50.js +19 -0
- package/dist/index.es.js +208 -16
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +208 -15
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/components/Switch/Switch.d.ts +13 -8
- package/dist/types/components/index.d.ts +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { SwitchProps as RadixSwitchProps } from "@radix-ui/react-switch";
|
|
3
|
+
import { FormControlProps } from "../_shared/cjs/FormControl-e6b7d7c5";
|
|
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,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 };
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Use `VerticalSpace` to create vertical space between components.
|
|
4
|
-
*/
|
|
5
|
-
declare const VerticalSpace: FC<VerticalSpaceProps>;
|
|
6
|
-
type VerticalSpaceSize = "4" | "8" | "12" | "16" | "24" | "32" | "48" | "64" | "96" | "128";
|
|
7
|
-
interface VerticalSpaceProps {
|
|
8
|
-
/**
|
|
9
|
-
* Should the VerticalSpace be visible for debugging and documentation
|
|
10
|
-
* purposes?
|
|
11
|
-
*/
|
|
12
|
-
isDebugVisible?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Size of the VerticalSpace.
|
|
15
|
-
*/
|
|
16
|
-
size?: VerticalSpaceSize;
|
|
17
|
-
}
|
|
18
|
-
export { VerticalSpace };
|
|
1
|
+
export { VerticalSpace } from "../_shared/cjs/VerticalSpace-65ad083c";
|
|
@@ -2,26 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var VerticalSpace = require('../_shared/cjs/VerticalSpace-65ad083c.js');
|
|
6
|
+
require('../_shared/cjs/index-78b35bc1.js');
|
|
7
|
+
require('../_shared/cjs/index-45bfb67b.js');
|
|
8
|
+
require('react');
|
|
8
9
|
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
10
|
|
|
11
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
* Use `VerticalSpace` to create vertical space between components.
|
|
15
|
-
*/
|
|
16
|
-
var VerticalSpace = function (_a) {
|
|
17
|
-
var _b;
|
|
18
|
-
var _c = _a.isDebugVisible, isDebugVisible = _c === void 0 ? false : _c, _d = _a.size, size = _d === void 0 ? "24" : _d, props = index.__rest(_a, ["isDebugVisible", "size"]);
|
|
19
|
-
return (React__default["default"].createElement("div", index.__assign({ className: index$1.classNames((_b = {
|
|
20
|
-
"arc-VerticalSpace": true
|
|
21
|
-
},
|
|
22
|
-
_b["arc-VerticalSpace--size".concat(size)] = size && size !== "24",
|
|
23
|
-
_b["arc-VerticalSpace--debugVisible"] = isDebugVisible,
|
|
24
|
-
_b)) }, index.filterDataAttrs(props))));
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
exports.VerticalSpace = VerticalSpace;
|
|
12
|
+
exports.VerticalSpace = VerticalSpace.VerticalSpace;
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Use `VerticalSpace` to create vertical space between components.
|
|
4
|
-
*/
|
|
5
|
-
declare const VerticalSpace: FC<VerticalSpaceProps>;
|
|
6
|
-
type VerticalSpaceSize = "4" | "8" | "12" | "16" | "24" | "32" | "48" | "64" | "96" | "128";
|
|
7
|
-
interface VerticalSpaceProps {
|
|
8
|
-
/**
|
|
9
|
-
* Should the VerticalSpace be visible for debugging and documentation
|
|
10
|
-
* purposes?
|
|
11
|
-
*/
|
|
12
|
-
isDebugVisible?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Size of the VerticalSpace.
|
|
15
|
-
*/
|
|
16
|
-
size?: VerticalSpaceSize;
|
|
17
|
-
}
|
|
18
|
-
export { VerticalSpace };
|
|
1
|
+
export { VerticalSpace } from "../_shared/esm/VerticalSpace-6b4f5e50";
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Use `VerticalSpace` to create vertical space between components.
|
|
7
|
-
*/
|
|
8
|
-
var VerticalSpace = function (_a) {
|
|
9
|
-
var _b;
|
|
10
|
-
var _c = _a.isDebugVisible, isDebugVisible = _c === void 0 ? false : _c, _d = _a.size, size = _d === void 0 ? "24" : _d, props = __rest(_a, ["isDebugVisible", "size"]);
|
|
11
|
-
return (React__default.createElement("div", __assign({ className: classNames((_b = {
|
|
12
|
-
"arc-VerticalSpace": true
|
|
13
|
-
},
|
|
14
|
-
_b["arc-VerticalSpace--size".concat(size)] = size && size !== "24",
|
|
15
|
-
_b["arc-VerticalSpace--debugVisible"] = isDebugVisible,
|
|
16
|
-
_b)) }, filterDataAttrs(props))));
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { VerticalSpace };
|
|
1
|
+
export { V as VerticalSpace } from '../_shared/esm/VerticalSpace-6b4f5e50.js';
|
|
2
|
+
import '../_shared/esm/index-229fc864.js';
|
|
3
|
+
import '../_shared/esm/index-2ae58626.js';
|
|
4
|
+
import 'react';
|