UNPKG

@kubit-ui-web/react-components

Version:

Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience

24 lines 2.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ToggleWithLabelStandAlone = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); const text_1 = require("../../components/text/text"); const useId_1 = require("../../hooks/useId/useId"); const screenReaderOnly_1 = require("../screenReaderOnly/screenReaderOnly"); const component_1 = require("../text/types/component"); const toggleControlled_1 = require("../toggle/toggleControlled"); const toggleWithLabel_styled_1 = require("./toggleWithLabel.styled"); const ToggleWithLabelStandAloneComponent = ({ screenReaderText, id, displayRow, styles, label, required, requiredSymbol, textVariant, toggleVariant, labelPosition, onFieldSetClick, dataTestId = 'toggle-with-label', ...props }, ref) => { const uniqueId = (0, useId_1.useId)('toggle'); const toggleId = id ?? uniqueId; const screenReaderId = `${uniqueId}ScreenReader`; const labelId = `${uniqueId}Label`; const legendStyles = props.disabled && styles?.legend?.disabled ? styles?.legend?.disabled : styles?.legend; return ((0, jsx_runtime_1.jsxs)(toggleWithLabel_styled_1.ToggleWithLabelStyled, { ref: ref, as: label ? 'fieldset' : 'div', "data-testid": dataTestId, displayRow: displayRow, labelPosition: labelPosition, styles: styles, onClick: onFieldSetClick, children: [label && ((0, jsx_runtime_1.jsxs)(text_1.Text, { component: component_1.TextComponentType.LEGEND, customTypography: legendStyles, id: labelId, variant: textVariant ?? styles?.legend?.font_variant, ...label, children: [label.content, required && ((0, jsx_runtime_1.jsx)(text_1.Text, { "aria-hidden": true, color: styles?.required?.color, component: component_1.TextComponentType.SPAN, variant: styles?.required?.font_variant, weight: styles?.required?.font_weight, ...requiredSymbol, children: requiredSymbol?.content }))] })), (0, jsx_runtime_1.jsx)(toggleControlled_1.ToggleControlled, { ...props, "aria-describedby": labelId, id: toggleId, screenReaderId: screenReaderId, variant: toggleVariant }), (0, jsx_runtime_1.jsx)(screenReaderOnly_1.ScreenReaderOnly, { id: screenReaderId, children: screenReaderText })] })); }; exports.ToggleWithLabelStandAlone = react_1.default.forwardRef(ToggleWithLabelStandAloneComponent); //# sourceMappingURL=toggleWithLabelStandAlone.js.map