@carbonid1/design-system 5.8.0 → 5.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import type { SegmentedControlItemProps, SegmentedControlRootProps } from './SegmentedControl.types';
2
+ export declare const SegmentedControl: {
3
+ Root: <Value extends string = string>({ value, onValueChange, size, orientation, className, children, ...props }: SegmentedControlRootProps<Value>) => import("react/jsx-runtime").JSX.Element;
4
+ Item: <Value extends string = string>({ className, size, ...props }: SegmentedControlItemProps<Value>) => import("react/jsx-runtime").JSX.Element;
5
+ };
@@ -0,0 +1,18 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Toggle as BaseToggle } from '@base-ui/react/toggle';
4
+ import { ToggleGroup as BaseToggleGroup } from '@base-ui/react/toggle-group';
5
+ import { createContext, useContext } from 'react';
6
+ import { buttonVariants } from '../Button/Button';
7
+ import { cn } from '../helpers/cn/cn';
8
+ const SegmentedControlContext = createContext({ size: 'small' });
9
+ const Root = ({ value, onValueChange, size = 'small', orientation = 'horizontal', className, children, ...props }) => (_jsx(BaseToggleGroup, { ...props, "data-slot": "segmented-control", multiple: false, orientation: orientation, value: [value], onValueChange: nextValues => onValueChange(nextValues[0] ?? value), className: cn('bg-surface-inset inset-shadow-surface flex w-fit gap-0.5 rounded-lg p-0.5', orientation === 'vertical' ? 'flex-col items-stretch' : 'items-center', className), children: _jsx(SegmentedControlContext.Provider, { value: { size }, children: children }) }));
10
+ const Item = ({ className, size, ...props }) => {
11
+ const context = useContext(SegmentedControlContext);
12
+ const resolvedSize = size ?? context.size;
13
+ return (_jsx(BaseToggle, { ...props, "data-slot": "segmented-control-item", className: state => cn(buttonVariants({ variant: 'ghost', size: resolvedSize, selected: state.pressed }), className) }));
14
+ };
15
+ export const SegmentedControl = {
16
+ Root,
17
+ Item,
18
+ };
@@ -0,0 +1,17 @@
1
+ import type { Toggle as BaseToggle } from '@base-ui/react/toggle';
2
+ import type { ToggleGroup as BaseToggleGroup } from '@base-ui/react/toggle-group';
3
+ export type SegmentedControlSize = 'small' | 'default' | 'large';
4
+ type BaseRootProps<Value extends string> = Omit<BaseToggleGroup.Props<Value>, 'className' | 'defaultValue' | 'multiple' | 'onValueChange' | 'value'>;
5
+ export type SegmentedControlRootProps<Value extends string = string> = BaseRootProps<Value> & {
6
+ value: Value;
7
+ onValueChange: (value: Value) => void;
8
+ size?: SegmentedControlSize;
9
+ className?: string;
10
+ };
11
+ type BaseItemProps<Value extends string> = Omit<BaseToggle.Props<Value>, 'className' | 'defaultPressed' | 'onPressedChange' | 'pressed' | 'value'>;
12
+ export type SegmentedControlItemProps<Value extends string = string> = BaseItemProps<Value> & {
13
+ value: Value;
14
+ size?: SegmentedControlSize;
15
+ className?: string;
16
+ };
17
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -9,6 +9,8 @@ export { Text, textVariants } from './Text/Text';
9
9
  export type { TextProps, TextPropsDefault } from './Text/Text.types';
10
10
  export { ProgressRing } from './ProgressRing/ProgressRing';
11
11
  export { Slider } from './Slider/Slider';
12
+ export { SegmentedControl } from './SegmentedControl/SegmentedControl';
13
+ export type { SegmentedControlItemProps, SegmentedControlRootProps, SegmentedControlSize, } from './SegmentedControl/SegmentedControl.types';
12
14
  export { ContextMenu } from './ContextMenu/ContextMenu';
13
15
  export { Select } from './Select/Select';
14
16
  export type { SelectOption, SelectGroup, SelectOptionState, SelectProps, } from './Select/Select.types';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export { Kbd, kbdVariants } from './Kbd/Kbd';
5
5
  export { Text, textVariants } from './Text/Text';
6
6
  export { ProgressRing } from './ProgressRing/ProgressRing';
7
7
  export { Slider } from './Slider/Slider';
8
+ export { SegmentedControl } from './SegmentedControl/SegmentedControl';
8
9
  export { ContextMenu } from './ContextMenu/ContextMenu';
9
10
  export { Select } from './Select/Select';
10
11
  export { Table } from './Table/Table';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carbonid1/design-system",
3
- "version": "5.8.0",
3
+ "version": "5.9.0",
4
4
  "description": "Shared React UI primitives + design tokens (themes, postcss config)",
5
5
  "repository": {
6
6
  "type": "git",