@react-spectrum/s2
Version:
Spectrum 2 UI components in React
112 lines (102 loc) • 5.62 kB
JavaScript
require("./ColorSwatch.css");
var $ac757a4c2bd72aee$exports = require("../icons/useSpectrumContextProps.cjs");
var $7Qhsa$reactjsxruntime = require("react/jsx-runtime");
var $7Qhsa$reactariacomponents = require("react-aria-components");
var $7Qhsa$react = require("react");
var $7Qhsa$reactspectrumutils = require("@react-spectrum/utils");
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "ColorSwatchContext", () => $8b1ea085cefae738$export$83cc445538396800);
$parcel$export(module.exports, "InternalColorSwatchContext", () => $8b1ea085cefae738$export$2d9e1fe7b5c0ceb6);
$parcel$export(module.exports, "ColorSwatch", () => $8b1ea085cefae738$export$cae13e90592f246a);
/*
* 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 $8b1ea085cefae738$export$83cc445538396800 = /*#__PURE__*/ (0, $7Qhsa$react.createContext)(null);
const $8b1ea085cefae738$export$2d9e1fe7b5c0ceb6 = /*#__PURE__*/ (0, $7Qhsa$react.createContext)(null);
const $8b1ea085cefae738$export$cae13e90592f246a = /*#__PURE__*/ (0, $7Qhsa$react.forwardRef)(function ColorSwatch(props, ref) {
[props, ref] = (0, $ac757a4c2bd72aee$exports.useSpectrumContextProps)(props, ref, $8b1ea085cefae738$export$83cc445538396800);
let domRef = (0, $7Qhsa$reactspectrumutils.useDOMRef)(ref);
let ctx = (0, $7Qhsa$react.useContext)($8b1ea085cefae738$export$2d9e1fe7b5c0ceb6);
let { size: size = ctx?.size || 'M', rounding: rounding = ctx?.rounding || 'default', color: color } = props;
let nonNullValue = color || '#fff0';
color = (0, $7Qhsa$react.useMemo)(()=>typeof nonNullValue === 'string' ? (0, $7Qhsa$reactariacomponents.parseColor)(nonNullValue) : nonNullValue, [
nonNullValue
]);
let swatch = /*#__PURE__*/ (0, $7Qhsa$reactjsxruntime.jsx)((0, $7Qhsa$reactariacomponents.ColorSwatch), {
...props,
color: color,
ref: domRef,
style: ({ color: color })=>({
// TODO: should there be a distinction between transparent and no value (e.g. null)?
background: color.getChannelValue('alpha') > 0 ? `linear-gradient(${color}, ${color}), repeating-conic-gradient(#e6e6e6 0% 25%, white 0% 50%) 0% 50% / 16px 16px` : 'linear-gradient(to bottom right, transparent calc(50% - 2px), var(--slash-color) calc(50% - 2px) calc(50% + 2px), transparent calc(50% + 2px)) no-repeat'
}),
className: function anonymous(props, overrides) {
let rules = " ";
let width = false;
let height = 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|F|M|K)[^\s]+/g);
for (let p of matches){
if (p[1] === "Z") width = true;
if (p[1] === "F") height = true;
rules += p[0];
}
if (props.size === "L") {
if (!width) rules += ' Zw91';
} else if (props.size === "M") {
if (!width) rules += ' ZC91';
} else if (props.size === "S") {
if (!width) rules += ' Zo91';
} else if (props.size === "XS") {
if (!width) rules += ' Zu91';
}
if (props.size === "L") {
if (!height) rules += ' Fv91';
} else if (props.size === "M") {
if (!height) rules += ' Fx91';
} else if (props.size === "S") {
if (!height) rules += ' Fp91';
} else if (props.size === "XS") {
if (!height) rules += ' Ft91';
}
if (props.rounding === "full") rules += ' og91';
else if (props.rounding === "none") rules += ' od91';
else if (props.rounding === "default") rules += ' oa91';
if (props.rounding === "full") rules += ' ng91';
else if (props.rounding === "none") rules += ' nd91';
else if (props.rounding === "default") rules += ' na91';
if (props.rounding === "full") rules += ' kg91';
else if (props.rounding === "none") rules += ' kd91';
else if (props.rounding === "default") rules += ' ka91';
if (props.rounding === "full") rules += ' jg91';
else if (props.rounding === "none") rules += ' jd91';
else if (props.rounding === "default") rules += ' ja91';
rules += ' iz91';
rules += ' _kb91';
rules += ' hb91';
rules += ' mb91';
rules += ' lb91';
rules += ' _jf91';
rules += ' _oa91';
rules += ' _yb91';
rules += ' -_8LZfRc-pq91';
return rules;
}({
size: size,
rounding: rounding
}, props.styles)
});
// ColorSwatchPicker needs to wrap the swatch in a ListBoxItem.
if (ctx) return ctx.useWrapper(swatch, color, rounding);
return swatch;
});
//# sourceMappingURL=ColorSwatch.cjs.map