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.

82 lines (79 loc) 2.5 kB
import { isString } from "../utils/assertion.js"; import { cs } from "../utils/styles.js"; import fontSizes_default from "../theme/foundations/fontSizes.js"; import { useStyleConfig } 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 { Fragment, jsx, jsxs } from "react/jsx-runtime"; //#region src/tagToggle/TagToggle.tsx const TagToggleBase = styled.buttonBox` align-items: center; cursor: pointer; display: inline-flex; font-weight: medium; justify-content: center; line-height: 1; position: relative; transition-duration: fast; user-select: none; width: fit-content; &:focus { outline: 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 themeVariant = isSelected ? `${variant}Selected` : variant; const styles = useStyleConfig("TagToggle", { ...props, variant: themeVariant }); const { h, fontSize: themeFontSize, paddingX = 0, paddingY = 0, gapX = 0, borderRadius, bgHover, bgPressed, ...containerColors } = styles.container ?? {}; const iconStyles = styles.icon ?? {}; const fontSize = `var(--vui-tag-font-size, ${fontSizes_default[themeFontSize] ?? themeFontSize}px)`; const pxX = `${paddingX}px`; const pxY = `${paddingY}px`; const pxGap = `${gapX}px`; return /* @__PURE__ */ jsx(TagToggleBase, { "aria-pressed": isSelected, borderRadius, className: cs("vui-tagToggle", className), focusRing: 2, fontSize, h, onClick: () => onChange?.(!isSelected), px: pxX, py: pxY, ref, type: "button", activeBg: bgPressed, hoverBg: bgHover, ...containerColors, ...rest, children: isString(icon) ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Icon, { className: "vui-tagToggleIcon", mr: label ? pxGap : void 0, name: icon, ...iconStyles }), label && /* @__PURE__ */ jsx(T, { className: "vui-tagToggleText", fontSize, children: label })] }) : label && /* @__PURE__ */ jsx(T, { className: "vui-tagToggleText", fontSize, children: label }) }); }); TagToggle.displayName = "TagToggle"; //#endregion export { TagToggle, TagToggle as default }; globalThis.__vuiVersion__ = "5.3.1" //# sourceMappingURL=TagToggle.js.map