228 lines
10 KiB
JavaScript
228 lines
10 KiB
JavaScript
var $k0DcK$react = require("react");
|
|
var $k0DcK$reactariaform = require("@react-aria/form");
|
|
var $k0DcK$reactstatelyform = require("@react-stately/form");
|
|
var $k0DcK$reactariatoggle = require("@react-aria/toggle");
|
|
var $k0DcK$reactariautils = require("@react-aria/utils");
|
|
var $k0DcK$reactarialabel = require("@react-aria/label");
|
|
var $k0DcK$reactariainteractions = require("@react-aria/interactions");
|
|
var $k0DcK$reactstatelytoggle = require("@react-stately/toggle");
|
|
|
|
|
|
function $parcel$export(e, n, v, s) {
|
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
}
|
|
|
|
$parcel$export(module.exports, "useCheckbox", () => $468c774d7db917b7$export$e375f10ce42261c5);
|
|
$parcel$export(module.exports, "useCheckboxGroup", () => $253685172d17db7d$export$49ff6f28c54f1cbe);
|
|
$parcel$export(module.exports, "useCheckboxGroupItem", () => $07e03121d6ac83c8$export$353b32fc6898d37d);
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/ /*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
|
|
|
|
|
|
function $468c774d7db917b7$export$e375f10ce42261c5(props, state, inputRef) {
|
|
// Create validation state here because it doesn't make sense to add to general useToggleState.
|
|
let validationState = (0, $k0DcK$reactstatelyform.useFormValidationState)({
|
|
...props,
|
|
value: state.isSelected
|
|
});
|
|
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
|
|
let { labelProps: labelProps, inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly } = (0, $k0DcK$reactariatoggle.useToggle)({
|
|
...props,
|
|
isInvalid: isInvalid
|
|
}, state, inputRef);
|
|
(0, $k0DcK$reactariaform.useFormValidation)(props, validationState, inputRef);
|
|
let { isIndeterminate: isIndeterminate, isRequired: isRequired, validationBehavior: validationBehavior = "aria" } = props;
|
|
(0, $k0DcK$react.useEffect)(()=>{
|
|
// indeterminate is a property, but it can only be set via javascript
|
|
// https://css-tricks.com/indeterminate-checkboxes/
|
|
if (inputRef.current) inputRef.current.indeterminate = !!isIndeterminate;
|
|
});
|
|
return {
|
|
labelProps: labelProps,
|
|
inputProps: {
|
|
...inputProps,
|
|
checked: isSelected,
|
|
"aria-required": isRequired && validationBehavior === "aria" || undefined,
|
|
required: isRequired && validationBehavior === "native"
|
|
},
|
|
isSelected: isSelected,
|
|
isPressed: isPressed,
|
|
isDisabled: isDisabled,
|
|
isReadOnly: isReadOnly,
|
|
isInvalid: isInvalid,
|
|
validationErrors: validationErrors,
|
|
validationDetails: validationDetails
|
|
};
|
|
}
|
|
|
|
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/ /*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/ const $64fc3370e682155f$export$ec98120685d4f57d = new WeakMap();
|
|
|
|
|
|
|
|
|
|
|
|
function $253685172d17db7d$export$49ff6f28c54f1cbe(props, state) {
|
|
let { isDisabled: isDisabled, name: name, validationBehavior: validationBehavior = "aria" } = props;
|
|
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
|
|
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $k0DcK$reactarialabel.useField)({
|
|
...props,
|
|
// Checkbox group is not an HTML input element so it
|
|
// shouldn't be labeled by a <label> element.
|
|
labelElementType: "span",
|
|
isInvalid: isInvalid,
|
|
errorMessage: props.errorMessage || validationErrors
|
|
});
|
|
(0, $64fc3370e682155f$export$ec98120685d4f57d).set(state, {
|
|
name: name,
|
|
descriptionId: descriptionProps.id,
|
|
errorMessageId: errorMessageProps.id,
|
|
validationBehavior: validationBehavior
|
|
});
|
|
let domProps = (0, $k0DcK$reactariautils.filterDOMProps)(props, {
|
|
labelable: true
|
|
});
|
|
let { focusWithinProps: focusWithinProps } = (0, $k0DcK$reactariainteractions.useFocusWithin)({
|
|
onBlurWithin: props.onBlur,
|
|
onFocusWithin: props.onFocus,
|
|
onFocusWithinChange: props.onFocusChange
|
|
});
|
|
return {
|
|
groupProps: (0, $k0DcK$reactariautils.mergeProps)(domProps, {
|
|
role: "group",
|
|
"aria-disabled": isDisabled || undefined,
|
|
...fieldProps,
|
|
...focusWithinProps
|
|
}),
|
|
labelProps: labelProps,
|
|
descriptionProps: descriptionProps,
|
|
errorMessageProps: errorMessageProps,
|
|
isInvalid: isInvalid,
|
|
validationErrors: validationErrors,
|
|
validationDetails: validationDetails
|
|
};
|
|
}
|
|
|
|
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
|
|
|
|
|
|
|
|
function $07e03121d6ac83c8$export$353b32fc6898d37d(props, state, inputRef) {
|
|
const toggleState = (0, $k0DcK$reactstatelytoggle.useToggleState)({
|
|
isReadOnly: props.isReadOnly || state.isReadOnly,
|
|
isSelected: state.isSelected(props.value),
|
|
onChange (isSelected) {
|
|
if (isSelected) state.addValue(props.value);
|
|
else state.removeValue(props.value);
|
|
if (props.onChange) props.onChange(isSelected);
|
|
}
|
|
});
|
|
let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $64fc3370e682155f$export$ec98120685d4f57d).get(state);
|
|
var _props_validationBehavior;
|
|
validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
|
|
// Local validation for this checkbox.
|
|
let { realtimeValidation: realtimeValidation } = (0, $k0DcK$reactstatelyform.useFormValidationState)({
|
|
...props,
|
|
value: toggleState.isSelected,
|
|
// Server validation is handled at the group level.
|
|
name: undefined,
|
|
validationBehavior: "aria"
|
|
});
|
|
// Update the checkbox group state when realtime validation changes.
|
|
let nativeValidation = (0, $k0DcK$react.useRef)((0, $k0DcK$reactstatelyform.DEFAULT_VALIDATION_RESULT));
|
|
let updateValidation = ()=>{
|
|
state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
|
|
};
|
|
(0, $k0DcK$react.useEffect)(updateValidation);
|
|
// Combine group and checkbox level validation.
|
|
let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
|
|
let displayValidation = validationBehavior === "native" ? state.displayValidation : combinedRealtimeValidation;
|
|
var _props_isRequired;
|
|
let res = (0, $468c774d7db917b7$export$e375f10ce42261c5)({
|
|
...props,
|
|
isReadOnly: props.isReadOnly || state.isReadOnly,
|
|
isDisabled: props.isDisabled || state.isDisabled,
|
|
name: props.name || name,
|
|
isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
|
|
validationBehavior: validationBehavior,
|
|
[(0, $k0DcK$reactstatelyform.privateValidationStateProp)]: {
|
|
realtimeValidation: combinedRealtimeValidation,
|
|
displayValidation: displayValidation,
|
|
resetValidation: state.resetValidation,
|
|
commitValidation: state.commitValidation,
|
|
updateValidation (v) {
|
|
nativeValidation.current = v;
|
|
updateValidation();
|
|
}
|
|
}
|
|
}, toggleState, inputRef);
|
|
return {
|
|
...res,
|
|
inputProps: {
|
|
...res.inputProps,
|
|
"aria-describedby": [
|
|
props["aria-describedby"],
|
|
state.isInvalid ? errorMessageId : null,
|
|
descriptionId
|
|
].filter(Boolean).join(" ") || undefined
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
|
|
|
|
//# sourceMappingURL=main.js.map
|