@react-spectrum/s2
Version:
Spectrum 2 UI components in React
101 lines (92 loc) • 5.26 kB
JavaScript
import "./ColorSwatchPicker.css";
import {InternalColorSwatchContext as $cd9e1720baab3945$export$2d9e1fe7b5c0ceb6} from "./ColorSwatch.mjs";
import {useSpectrumContextProps as $5ce63c423902f47d$export$764f6146fadd77f7} from "../icons/useSpectrumContextProps.mjs";
import {jsx as $bOBHx$jsx, jsxs as $bOBHx$jsxs, Fragment as $bOBHx$Fragment} from "react/jsx-runtime";
import {ColorSwatchPicker as $bOBHx$ColorSwatchPicker, ColorSwatchPickerItem as $bOBHx$ColorSwatchPickerItem} from "react-aria-components";
import {createContext as $bOBHx$createContext, forwardRef as $bOBHx$forwardRef} from "react";
import {useDOMRef as $bOBHx$useDOMRef} 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 $ba9c901b6c815fb9$export$7214f50881fc1eaf = /*#__PURE__*/ (0, $bOBHx$createContext)(null);
const $ba9c901b6c815fb9$export$b46792416e3d8515 = /*#__PURE__*/ (0, $bOBHx$forwardRef)(function ColorSwatchPicker(props, ref) {
[props, ref] = (0, $5ce63c423902f47d$export$764f6146fadd77f7)(props, ref, $ba9c901b6c815fb9$export$7214f50881fc1eaf);
let { density: density = 'regular', size: size = 'M', rounding: rounding = 'none', UNSAFE_className: UNSAFE_className = '', ...otherProps } = props;
let domRef = (0, $bOBHx$useDOMRef)(ref);
return /*#__PURE__*/ (0, $bOBHx$jsx)((0, $bOBHx$ColorSwatchPicker), {
...otherProps,
ref: domRef,
className: UNSAFE_className + function anonymous(props, overrides) {
let rules = " ";
rules += ((overrides || '').match(/(?:^|\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) || []).join('');
rules += ' sd91';
rules += ' _wb91';
if (props.density === "spacious") rules += ' UWJpoB91';
else if (props.density === "regular") rules += ' Ub91';
else if (props.density === "compact") rules += ' Ua91';
if (props.density === "spacious") rules += ' qWJpoB91';
else if (props.density === "regular") rules += ' qb91';
else if (props.density === "compact") rules += ' qa91';
return rules;
}({
density: density
}, props.styles),
children: /*#__PURE__*/ (0, $bOBHx$jsx)((0, $cd9e1720baab3945$export$2d9e1fe7b5c0ceb6).Provider, {
value: {
useWrapper: $ba9c901b6c815fb9$var$useWrapper,
size: size,
rounding: rounding
},
children: props.children
})
});
});
function $ba9c901b6c815fb9$var$useWrapper(swatch, color, rounding) {
return /*#__PURE__*/ (0, $bOBHx$jsx)((0, $bOBHx$ColorSwatchPickerItem), {
color: color,
className: (renderProps)=>(function anonymous(props) {
let rules = " ";
if (props.isFocusVisible) rules += ' _Lf91';
else rules += ' _Le91';
rules += ' Oh91';
rules += ' _Mc91';
rules += ' _Kd91';
rules += ' _Pc91';
if (props.rounding === "full") rules += ' og91';
else if (props.rounding === "default") rules += ' oa91';
else if (props.rounding === "none") rules += ' od91';
if (props.rounding === "full") rules += ' ng91';
else if (props.rounding === "default") rules += ' na91';
else if (props.rounding === "none") rules += ' nd91';
if (props.rounding === "full") rules += ' kg91';
else if (props.rounding === "default") rules += ' ka91';
else if (props.rounding === "none") rules += ' kd91';
if (props.rounding === "full") rules += ' jg91';
else if (props.rounding === "default") rules += ' ja91';
else if (props.rounding === "none") rules += ' jd91';
return rules;
})({
...renderProps,
rounding: rounding
}),
children: ({ isSelected: isSelected })=>/*#__PURE__*/ (0, $bOBHx$jsxs)((0, $bOBHx$Fragment), {
children: [
swatch,
isSelected && /*#__PURE__*/ (0, $bOBHx$jsx)("div", {
"aria-hidden": true,
className: " _Pa91 _Ob91 Wr91 _lr91 _Ar91 _zr91 _oa91 in91 _jf91 _kc91 hc91 mc91 lc91 Og91 _Lf91 _Mc91 _Kc91 _yb91 oi91 ni91 ki91 ji91"
})
]
})
});
}
export {$ba9c901b6c815fb9$export$7214f50881fc1eaf as ColorSwatchPickerContext, $ba9c901b6c815fb9$export$b46792416e3d8515 as ColorSwatchPicker};
//# sourceMappingURL=ColorSwatchPicker.mjs.map