@atlaskit/checkbox
Version:
A checkbox is an input control that allows a user to select one or more options from a number of choices.
83 lines (81 loc) • 3.17 kB
JavaScript
/* checkbox-icon.tsx generated by @compiled/babel-plugin v3.0.2 */
import "./checkbox-icon.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { Fragment, memo, useMemo } from 'react';
import { fg } from '@atlaskit/platform-feature-flags/fg';
/**
* Styles for the checkbox icon.
* CSS custom properties for colors are set by the parent Label element
* and consumed directly in these styles.
*/
var svgStyles = {
root: "_nd5lfibj _1reo15vq _18m915vq _v5641mn3 _2rko12b0 _1a3742bt _lcxvglyw _syazmov0 _lswu1kgh _1cwg1i6y",
rect: "_v56411so _1snbe4h9 _1s17hteq"
};
// Cross-fade colors and glyphs without moving the input or focus outline.
// Semantic tokens keep SVG colors, borders and indicators aligned with input motion.
// Preserve non-spatial transitions for reduced motion, per the LDR:
// https://hello.atlassian.net/wiki/spaces/DST/pages/7402790985
var motionStyles = {
root: "_v564109b",
selected: "_tzy4kb7n",
glyph: "_v564109b _tzy4idpf _1hdqglyw",
border: "_v564109b"
};
function getIcon(isIndeterminate, isChecked, motionState) {
if (isIndeterminate) {
return /*#__PURE__*/React.createElement("path", {
fillRule: "evenodd",
clipRule: "evenodd",
d: "M7.75 12.75H16.25V11.25H7.75V12.75Z",
fill: "inherit",
className: ax([motionState && motionStyles.glyph, motionState === 'visible' && motionStyles.selected])
});
}
if (isChecked) {
return /*#__PURE__*/React.createElement("path", {
fillRule: "evenodd",
clipRule: "evenodd",
d: "M16.3262 9.48011L15.1738 8.51984L10.75 13.8284L8.82616 11.5198L7.67383 12.4801L10.1738 15.4801C10.3163 15.6511 10.5274 15.75 10.75 15.75C10.9726 15.75 11.1837 15.6511 11.3262 15.4801L16.3262 9.48011Z",
fill: "inherit",
className: ax([motionState && motionStyles.glyph, motionState === 'visible' && motionStyles.selected])
});
}
// No icon
return null;
}
/**
* __Checkbox icon__
*
* A checkbox icon is the visual representation of checkbox state,
* which is shown instead of the native input.
*
* @internal
*/
var CheckboxIcon = /*#__PURE__*/memo(function (_ref) {
var isIndeterminate = _ref.isIndeterminate,
isChecked = _ref.isChecked;
var hasMotion = fg('platform_design_system_selection_radial_fade');
var icon = useMemo(function () {
return getIcon(isIndeterminate, isChecked);
}, [isIndeterminate, isChecked]);
return /*#__PURE__*/React.createElement("svg", {
width: 24,
height: 24,
viewBox: "0 0 24 24",
role: "presentation",
className: ax([svgStyles.root, hasMotion && motionStyles.root])
}, /*#__PURE__*/React.createElement("g", {
fillRule: "evenodd"
}, /*#__PURE__*/React.createElement("rect", {
fill: "currentColor",
x: "5.5",
y: "5.5",
width: "13",
height: "13",
rx: "1.5",
className: ax([svgStyles.rect, hasMotion && motionStyles.border])
}), hasMotion ? /*#__PURE__*/React.createElement(Fragment, null, getIcon(false, true, isChecked && !isIndeterminate ? 'visible' : 'hidden'), getIcon(true, false, isIndeterminate ? 'visible' : 'hidden')) : icon));
});
export default CheckboxIcon;