add grow prop to segmented control
This commit is contained in:
parent
e7cc7384ce
commit
76484b7bb0
3 changed files with 11 additions and 2 deletions
|
|
@ -17,9 +17,10 @@
|
||||||
|
|
||||||
let { value, class: className, disabled, children: content }: Props = $props()
|
let { value, class: className, disabled, children: content }: Props = $props()
|
||||||
|
|
||||||
// Get variant and size from parent context
|
// Get variant, size, and grow from parent context
|
||||||
const variant = getContext<SegmentedControlVariant>('segmented-control-variant') || 'default'
|
const variant = getContext<SegmentedControlVariant>('segmented-control-variant') || 'default'
|
||||||
const size = getContext<SegmentedControlSize>('segmented-control-size') || 'default'
|
const size = getContext<SegmentedControlSize>('segmented-control-size') || 'default'
|
||||||
|
const grow = getContext<boolean>('segmented-control-grow') || false
|
||||||
|
|
||||||
// Apply variant-specific classes
|
// Apply variant-specific classes
|
||||||
const variantClasses = {
|
const variantClasses = {
|
||||||
|
|
@ -39,6 +40,7 @@
|
||||||
styles.segment,
|
styles.segment,
|
||||||
variantClasses[variant],
|
variantClasses[variant],
|
||||||
sizeClasses[size],
|
sizeClasses[size],
|
||||||
|
grow ? styles.grow : '',
|
||||||
className || ''
|
className || ''
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,10 @@
|
||||||
children
|
children
|
||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
|
|
||||||
// Provide variant and size to child segments via context
|
// Provide variant, size, and grow to child segments via context
|
||||||
setContext('segmented-control-variant', variant)
|
setContext('segmented-control-variant', variant)
|
||||||
setContext('segmented-control-size', size)
|
setContext('segmented-control-size', size)
|
||||||
|
setContext('segmented-control-grow', grow)
|
||||||
|
|
||||||
// Track previous value to only fire callback on actual changes (not initialization)
|
// Track previous value to only fire callback on actual changes (not initialization)
|
||||||
let previousValue = $state<string | undefined>(undefined)
|
let previousValue = $state<string | undefined>(undefined)
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Grow variant - fill available space equally
|
||||||
|
.grow {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.label {
|
.label {
|
||||||
border: 0.5px solid transparent;
|
border: 0.5px solid transparent;
|
||||||
border-radius: layout.$full-corner;
|
border-radius: layout.$full-corner;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue