@react-spectrum/s2
Version:
Spectrum 2 UI components in React
151 lines (141 loc) • 7.7 kB
JavaScript
import "./ColorField.css";
import {FieldErrorIcon as $9afd80978c252040$export$bda0d075e0e342c9, FieldGroup as $9afd80978c252040$export$f0fe469072bc6950, FieldLabel as $9afd80978c252040$export$1acdcf5a973a8414, HelpText as $9afd80978c252040$export$a67c0bc59081311a, Input as $9afd80978c252040$export$f5b8910cec6cf069} from "./Field.mjs";
import {FormContext as $9b916426527cebe7$export$c24727297075ec6a, useFormProps as $9b916426527cebe7$export$a6b5be5c6b451665} from "./Form.mjs";
import {useSpectrumContextProps as $5ce63c423902f47d$export$764f6146fadd77f7} from "../icons/useSpectrumContextProps.mjs";
import {jsx as $Y0ll1$jsx, jsxs as $Y0ll1$jsxs, Fragment as $Y0ll1$Fragment} from "react/jsx-runtime";
import {ColorField as $Y0ll1$ColorField} from "react-aria-components";
import {createContext as $Y0ll1$createContext, forwardRef as $Y0ll1$forwardRef, useContext as $Y0ll1$useContext, useRef as $Y0ll1$useRef, useImperativeHandle as $Y0ll1$useImperativeHandle} from "react";
import {createFocusableRef as $Y0ll1$createFocusableRef} from "@react-spectrum/utils";
/*
* Copyright 2024 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 $9c5ed7ec0bc126af$export$44644b8a16031b5b = /*#__PURE__*/ (0, $Y0ll1$createContext)(null);
const $9c5ed7ec0bc126af$export$b865d4358897bb17 = /*#__PURE__*/ (0, $Y0ll1$forwardRef)(function ColorField(props, ref) {
[props, ref] = (0, $5ce63c423902f47d$export$764f6146fadd77f7)(props, ref, $9c5ed7ec0bc126af$export$44644b8a16031b5b);
let formContext = (0, $Y0ll1$useContext)((0, $9b916426527cebe7$export$c24727297075ec6a));
props = (0, $9b916426527cebe7$export$a6b5be5c6b451665)(props);
let { label: label, description: description, errorMessage: errorMessage, necessityIndicator: necessityIndicator, labelPosition: labelPosition = 'top', labelAlign: labelAlign = 'start', UNSAFE_style: UNSAFE_style, UNSAFE_className: UNSAFE_className = '', styles: styles, ...fieldProps } = props;
// Expose imperative interface for ref
let domRef = (0, $Y0ll1$useRef)(null);
let inputRef = (0, $Y0ll1$useRef)(null);
(0, $Y0ll1$useImperativeHandle)(ref, ()=>({
...(0, $Y0ll1$createFocusableRef)(domRef, inputRef),
select () {
if (inputRef.current) inputRef.current.select();
},
getInputElement () {
return inputRef.current;
}
}));
return /*#__PURE__*/ (0, $Y0ll1$jsx)((0, $Y0ll1$ColorField), {
...fieldProps,
ref: domRef,
style: UNSAFE_style,
className: UNSAFE_className + function anonymous(props, overrides) {
let rules = " ";
let gridColumnStart = false;
let gridColumnEnd = false;
let matches = (overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|Z|N|L)[^\s]+/g);
for (let p of matches){
if (p[1] === "z") gridColumnStart = true;
if (p[1] === "y") gridColumnEnd = true;
rules += p[0];
}
rules += ' se91';
if (props.isInForm) {
if (!gridColumnStart) rules += ' z2mU91';
}
if (props.isInForm) {
if (props.labelPosition === "side") {
if (!gridColumnEnd) rules += ' yvoofG91';
}
}
if (props.isInForm) rules += ' DLwlgod91';
else {
if (props.labelPosition === "side") rules += ' DPlN5qb91';
else if (props.labelPosition === "top") rules += ' DM8Mfn91';
}
if (props.labelPosition === "side") rules += ' EPlN5qb91';
else if (props.labelPosition === "top") rules += ' E4w1sLc91';
if (props.labelPosition === "side") rules += ' CbRM95c91';
else if (props.labelPosition === "top") rules += ' Cxaocre91';
if (props.size === "XL") {
rules += ' vg91';
rules += ' vsj91';
} else if (props.size === "L") {
rules += ' vp91';
rules += ' vsh91';
} else if (props.size === "S") {
rules += ' vb91';
rules += ' vse91';
} else if (props.size === "XS") {
rules += ' va91';
rules += ' vsc91';
} else {
rules += ' vd91';
rules += ' vsf91';
}
rules += ' ea91';
rules += ' _Fa91';
rules += ' _Ffb91';
if (props.size === "XL") rules += ' -BhX7R-Fz91';
else if (props.size === "L") rules += ' -BhX7R-Fv91';
else if (props.size === "S") rules += ' -BhX7R-Fp91';
else if (props.size === "XS") rules += ' -BhX7R-Fn91';
else rules += ' -BhX7R-Fx91';
rules += ' -AJjOLd-UVkF0Db91';
rules += ' qg91';
rules += ' __ca91';
return rules;
}({
size: props.size,
labelPosition: labelPosition,
isInForm: !!formContext
}, styles),
children: ({ isDisabled: isDisabled, isInvalid: isInvalid })=>/*#__PURE__*/ (0, $Y0ll1$jsxs)((0, $Y0ll1$Fragment), {
children: [
/*#__PURE__*/ (0, $Y0ll1$jsx)((0, $9afd80978c252040$export$1acdcf5a973a8414), {
isDisabled: isDisabled,
isRequired: props.isRequired,
size: props.size,
labelPosition: labelPosition,
labelAlign: labelAlign,
necessityIndicator: necessityIndicator,
contextualHelp: props.contextualHelp,
children: label
}),
/*#__PURE__*/ (0, $Y0ll1$jsxs)((0, $9afd80978c252040$export$f0fe469072bc6950), {
role: "presentation",
isDisabled: isDisabled,
isInvalid: isInvalid,
size: props.size,
children: [
/*#__PURE__*/ (0, $Y0ll1$jsx)((0, $9afd80978c252040$export$f5b8910cec6cf069), {
ref: inputRef
}),
isInvalid && /*#__PURE__*/ (0, $Y0ll1$jsx)((0, $9afd80978c252040$export$bda0d075e0e342c9), {
isDisabled: isDisabled
})
]
}),
/*#__PURE__*/ (0, $Y0ll1$jsx)((0, $9afd80978c252040$export$a67c0bc59081311a), {
size: props.size,
isDisabled: isDisabled,
isInvalid: isInvalid,
description: description,
children: errorMessage
})
]
})
});
});
export {$9c5ed7ec0bc126af$export$44644b8a16031b5b as ColorFieldContext, $9c5ed7ec0bc126af$export$b865d4358897bb17 as ColorField};
//# sourceMappingURL=ColorField.mjs.map