UNPKG

@veracity/vui

Version:

Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.

69 lines (66 loc) 2.11 kB
import { isString } from "../utils/assertion.js"; import { cs } from "../utils/styles.js"; import { useStyleConfig, useTh } from "../core/theme.js"; import styled from "../core/styled.js"; import vui from "../core/vui.js"; import { Icon } from "../icon/icon.js"; import { T } from "../t/t.js"; import { tagPillBaseCss } from "../tag/tagPillBase.css.js"; import { jsx, jsxs } from "react/jsx-runtime"; //#region src/tagToggle/TagToggle.tsx const TagToggleBase = styled.buttonBox` ${tagPillBaseCss} cursor: pointer; user-select: none; `; /** * A toggle button styled as a tag. Uses brand-only colour tokens and an * `aria-pressed` attribute to convey selected state. */ const TagToggle = vui((props, ref) => { const { className, icon, isSelected = false, label, onChange, variant = "solid", ...rest } = props; const styles = useStyleConfig("TagToggle", { ...props, variant }); const { selected, ...container } = styles.container ?? {}; const { h, fontSize: themeFontSize, paddingX = 0, paddingY = 0, gapX = 0, borderRadius, bgHover, bgPressed, ...containerColors } = isSelected ? { ...container, ...selected } : container; const iconStyles = styles.icon ?? {}; const fontSize = `var(--vui-tag-font-size, ${useTh(`fontSizes.${themeFontSize}`, themeFontSize)}px)`; const toPx = (n) => `${n}px`; return /* @__PURE__ */ jsxs(TagToggleBase, { "aria-pressed": isSelected, borderRadius, className: cs("vui-tagToggle", className), focusRing: 2, fontSize, gap: toPx(gapX), h, onClick: () => onChange?.(!isSelected), px: toPx(paddingX), py: toPx(paddingY), ref, type: "button", activeBg: bgPressed, hoverBg: bgHover, ...containerColors, ...rest, children: [isString(icon) && /* @__PURE__ */ jsx(Icon, { className: "vui-tagToggleIcon", name: icon, ...iconStyles }), label && /* @__PURE__ */ jsx(T, { className: "vui-tagToggleText", fontSize, children: label })] }); }); TagToggle.displayName = "TagToggle"; //#endregion export { TagToggle, TagToggle as default }; globalThis.__vuiVersion__ = "5.4.0-alpha" //# sourceMappingURL=TagToggle.js.map