UNPKG

@porsche-design-system/components-react

Version:

Porsche Design System is a component library designed to help developers create the best experience for software or services distributed by Dr. Ing. h.c. F. Porsche AG.

47 lines (43 loc) 4.21 kB
'use strict'; var jsxRuntime = require('react/jsx-runtime'); var react = require('react'); require('../../provider.cjs'); var splitChildren = require('../../splitChildren.cjs'); var minifyCss = require('../../minifyCss.cjs'); var stylesEntry = require('../../../../../../components/dist/styles/esm/styles-entry.cjs'); var utilsEntry = require('../../../../../../components/dist/utils/esm/utils-entry.cjs'); var label = require('./label.cjs'); var stateMessage = require('./state-message.cjs'); var scroller_wrapper = require('../components/scroller.wrapper.cjs'); /** * @slot {"name": "label", "description": "Shows a label. Only [phrasing content](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content) is allowed."} * @slot {"name": "label-after", "description": "Places additional content after the label text (for content that should not be part of the label, e.g. external links or `p-popover`)."} * @slot {"name": "description", "description": "Shows a description. Only [phrasing content](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content) is allowed."} * @slot {"name": "", "description": "Default slot for the `p-segmented-control-item` tags." } * @slot {"name": "message", "description": "Shows a state message. Only [phrasing content](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content) is allowed."} * * @controlled { "props": ["value"], "event": "update", "isInternallyMutated": true } */ class DSRSegmentedControl extends react.Component { host; internals; defaultValue; formResetCallback() { this.props.internals?.setFormValue(this.props.defaultValue?.toString()); } formDisabledCallback() { // Called when a parent fieldset is disabled or enabled } formStateRestoreCallback() { } render() { const { children, namedSlotChildren, otherChildren } = splitChildren.splitChildren(this.props.children); const manipulatedChildren = children.map((child) => typeof child === 'object' && 'props' in child && otherChildren.includes(child) ? { ...child, props: { ...child.props, selected: child.props?.value === this.props.value, backgroundColor: this.props.backgroundColor, theme: this.props.theme } } : child); const itemWidths = this.props.noWrap ? undefined : { minWidth: 100, maxWidth: 100 }; const style = minifyCss.minifyCss(stylesEntry.getSegmentedControlCss(itemWidths?.minWidth, itemWidths?.maxWidth, this.props.columns, this.props.disabled, this.props.hideLabel, this.props.state, this.props.theme, this.props.noWrap)); return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("template", { shadowroot: "open", shadowrootmode: "open", children: [jsxRuntime.jsx("style", { dangerouslySetInnerHTML: { __html: style } }), jsxRuntime.jsxs("fieldset", { inert: this.props.disabled, disabled: this.props.disabled, ...utilsEntry.getFieldsetAriaAttributes(this.props.required, this.props.state === 'error'), "aria-labelledby": utilsEntry.labelId, "aria-describedby": utilsEntry.descriptionId, className: "root", children: [jsxRuntime.jsx(label.Label, { hasLabel: this.props.label || namedSlotChildren.filter(({ props: { slot } }) => slot === 'label').length > 0, hasDescription: this.props.description || namedSlotChildren.filter(({ props: { slot } }) => slot === 'description').length > 0, host: null, tag: "div", label: this.props.label, description: this.props.description, isRequired: this.props.required, isDisabled: this.props.disabled }), this.props.noWrap ? (jsxRuntime.jsx(scroller_wrapper.PScroller, { theme: this.props.theme, className: "scroller", children: jsxRuntime.jsx("slot", {}) })) : (jsxRuntime.jsx("slot", {})), jsxRuntime.jsx(stateMessage.StateMessage, { hasMessage: (this.props.message || namedSlotChildren.filter(({ props: { slot } }) => slot === 'message').length > 0) && ['success', 'error'].includes(this.props.state), state: this.props.state, message: this.props.message, theme: this.props.theme, host: null })] })] }), manipulatedChildren] })); } } exports.DSRSegmentedControl = DSRSegmentedControl;