Update SegmentedControl

* Forward refs to SegmentedControl
* Allow passing of className via props
* Specific styles for RaidCombobox and something else
* Use small-tablet breakpoint
This commit is contained in:
Justin Edmund 2023-06-30 22:25:09 -07:00
parent 938b17e5e9
commit 3fbd4aac69
2 changed files with 44 additions and 16 deletions

View file

@ -2,20 +2,24 @@
display: flex; display: flex;
justify-content: center; justify-content: center;
@include breakpoint(phone) { &.raid {
width: 100%;
}
@include breakpoint(small-tablet) {
width: 100%; width: 100%;
} }
.segmentedControl { .segmentedControl {
// border-radius: $unit * 3;
display: inline-flex; display: inline-flex;
padding: 3px; padding: 3px;
position: relative; position: relative;
gap: $unit-half;
user-select: none; user-select: none;
overflow: hidden; overflow: hidden;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
@include breakpoint(phone) { @include breakpoint(small-tablet) {
background: var(--card-bg); background: var(--card-bg);
border-radius: 100px; border-radius: 100px;
} }
@ -25,6 +29,11 @@
border-radius: $full-corner; border-radius: $full-corner;
} }
&.background {
background: var(--input-bg);
border-radius: $full-corner;
}
&.grow { &.grow {
flex-grow: 1; flex-grow: 1;
} }
@ -33,6 +42,10 @@
gap: $unit; gap: $unit;
} }
&.raid {
width: 100%;
}
&.fire { &.fire {
.Segment input:checked + label { .Segment input:checked + label {
background: var(--fire-bg); background: var(--fire-bg);

View file

@ -1,9 +1,10 @@
import React from 'react' import React, { PropsWithChildren } from 'react'
import classNames from 'classnames' import classNames from 'classnames'
import styles from './index.module.scss' import styles from './index.module.scss'
interface Props { interface Props {
className?: string className?: string
wrapperClassName?: string
elementClass?: string elementClass?: string
blended?: boolean blended?: boolean
grow?: boolean grow?: boolean
@ -11,15 +12,29 @@ interface Props {
tabIndex?: number tabIndex?: number
} }
const SegmentedControl: React.FC<Props> = ({ const SegmentedControl = React.forwardRef<
HTMLDivElement,
PropsWithChildren<Props>
>(function SegmentedControl(
{
className, className,
wrapperClassName,
elementClass, elementClass,
blended, blended,
grow, grow,
gap, gap,
tabIndex, tabIndex,
children, children,
}) => { },
forwardedRef
) {
const wrapperClasses = classNames(
{
[styles.wrapper]: true,
},
wrapperClassName?.split(' ').map((className) => styles[className])
)
const classes = classNames( const classes = classNames(
{ {
[styles.segmentedControl]: true, [styles.segmentedControl]: true,
@ -28,15 +43,15 @@ const SegmentedControl: React.FC<Props> = ({
[styles.gap]: gap, [styles.gap]: gap,
blended: blended, blended: blended,
}, },
className, className?.split(' ').map((className) => styles[className]),
elementClass elementClass
) )
return ( return (
<div className={styles.wrapper} tabIndex={tabIndex}> <div className={wrapperClasses} tabIndex={tabIndex} ref={forwardedRef}>
<div className={classes}>{children}</div> <div className={classes}>{children}</div>
</div> </div>
) )
} })
SegmentedControl.defaultProps = { SegmentedControl.defaultProps = {
blended: false, blended: false,