-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Segmented Control styled 레이어 추가, useSize 의존성 제거
- Loading branch information
Showing
26 changed files
with
735 additions
and
588 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { SegmentedControl, Segment } from "seed-design/ui/segmented-control"; | ||
import { SegmentedControl, SegmentedControlSegment } from "seed-design/ui/segmented-control"; | ||
|
||
export default function SegmentedControlPreview() { | ||
return ( | ||
<SegmentedControl defaultValue="Hot" disabled> | ||
<Segment value="Hot">Hot</Segment> | ||
<Segment value="New">New</Segment> | ||
<SegmentedControl defaultValue="Hot" disabled aria-label="Sort by"> | ||
<SegmentedControlSegment value="Hot">Hot</SegmentedControlSegment> | ||
<SegmentedControlSegment value="New">New</SegmentedControlSegment> | ||
</SegmentedControl> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { SegmentedControl, Segment } from "seed-design/ui/segmented-control"; | ||
import { SegmentedControl, SegmentedControlSegment } from "seed-design/ui/segmented-control"; | ||
|
||
export default function SegmentedControlFixedWidth() { | ||
return ( | ||
<SegmentedControl defaultValue="new"> | ||
<Segment value="new">New</Segment> | ||
<Segment value="hot">Hot</Segment> | ||
<SegmentedControl defaultValue="new" style={{ width: "600px" }} aria-label="Sort by"> | ||
<SegmentedControlSegment value="new">New</SegmentedControlSegment> | ||
<SegmentedControlSegment value="hot">Hot</SegmentedControlSegment> | ||
</SegmentedControl> | ||
); | ||
} |
10 changes: 5 additions & 5 deletions
10
docs/components/example/segmented-control-long-label-fixed-width.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { SegmentedControl, Segment } from "seed-design/ui/segmented-control"; | ||
import { SegmentedControl, SegmentedControlSegment } from "seed-design/ui/segmented-control"; | ||
|
||
export default function SegmentedControlLongLabelFixedWidth() { | ||
return ( | ||
<SegmentedControl defaultValue="price"> | ||
<Segment value="price">가격 높은 순</Segment> | ||
<Segment value="discount">할인율 높은 순</Segment> | ||
<Segment value="popularity">인기 많은 순</Segment> | ||
<SegmentedControl defaultValue="price" style={{ width: "600px" }} aria-label="정렬 기준"> | ||
<SegmentedControlSegment value="price">가격 높은 순</SegmentedControlSegment> | ||
<SegmentedControlSegment value="discount">할인율 높은 순</SegmentedControlSegment> | ||
<SegmentedControlSegment value="popularity">인기 많은 순</SegmentedControlSegment> | ||
</SegmentedControl> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { SegmentedControl, Segment } from "seed-design/ui/segmented-control"; | ||
import { SegmentedControl, SegmentedControlSegment } from "seed-design/ui/segmented-control"; | ||
|
||
export default function SegmentedControlLongLabel() { | ||
return ( | ||
<SegmentedControl defaultValue="price"> | ||
<Segment value="price">가격 높은 순</Segment> | ||
<Segment value="discount">할인율 높은 순</Segment> | ||
<Segment value="popularity">인기 많은 순</Segment> | ||
<SegmentedControl defaultValue="price" aria-label="정렬 기준"> | ||
<SegmentedControlSegment value="price">가격 높은 순</SegmentedControlSegment> | ||
<SegmentedControlSegment value="discount">할인율 높은 순</SegmentedControlSegment> | ||
<SegmentedControlSegment value="popularity">인기 많은 순</SegmentedControlSegment> | ||
</SegmentedControl> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { SegmentedControl, Segment } from "seed-design/ui/segmented-control"; | ||
import { SegmentedControl, SegmentedControlSegment } from "seed-design/ui/segmented-control"; | ||
|
||
export default function SegmentedControlPreview() { | ||
return ( | ||
<SegmentedControl defaultValue="Hot"> | ||
<Segment value="Hot">Hot</Segment> | ||
<Segment value="New">New</Segment> | ||
<SegmentedControl defaultValue="Hot" aria-label="Sort by"> | ||
<SegmentedControlSegment value="Hot">Hot</SegmentedControlSegment> | ||
<SegmentedControlSegment value="New">New</SegmentedControlSegment> | ||
</SegmentedControl> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,58 @@ | ||
"use client"; | ||
|
||
import "@seed-design/stylesheet/segmentedControl.css"; | ||
import { | ||
useSegmentedControl, | ||
type SegmentItemProps, | ||
type UseSegmentedControlProps, | ||
} from "@seed-design/react-segmented-control"; | ||
import * as React from "react"; | ||
import clsx from "clsx"; | ||
import { | ||
segmentedControl, | ||
type SegmentedControlVariantProps, | ||
} from "@seed-design/recipe/segmentedControl"; | ||
import type { Assign } from "../util/types"; | ||
import { visuallyHidden } from "../util/visuallyHidden"; | ||
|
||
const SegmentedControlContext = React.createContext<{ | ||
api: ReturnType<typeof useSegmentedControl>; | ||
} | null>(null); | ||
|
||
const useSegmentedControlContext = () => { | ||
const context = React.useContext(SegmentedControlContext); | ||
if (!context) | ||
throw new Error("Segment cannot be rendered outside the SegmentedControl"); | ||
|
||
return context; | ||
}; | ||
import { SegmentedControl as SeedSegmentedControl } from "@seed-design/react"; | ||
import * as React from "react"; | ||
|
||
export type SegmentedControlProps = Assign< | ||
React.HTMLAttributes<HTMLDivElement>, | ||
UseSegmentedControlProps | ||
> & | ||
SegmentedControlVariantProps & {}; | ||
export interface SegmentedControlProps extends SeedSegmentedControl.RootProps {} | ||
|
||
export const SegmentedControl = React.forwardRef< | ||
HTMLDivElement, | ||
SegmentedControlProps | ||
>(({ className, children, ...otherProps }, ref) => { | ||
const api = useSegmentedControl(otherProps); | ||
|
||
const { rootProps, restProps, indicatorProps } = api; | ||
|
||
const classNames = segmentedControl(); | ||
>(({ children, ...otherProps }, ref) => { | ||
if (!otherProps["aria-label"] && !otherProps["aria-labelledby"]) { | ||
console.warn( | ||
"SegmentedControl component requires either an `aria-label` or `aria-labelledby` attribute.", | ||
); | ||
} | ||
|
||
const [mounted, setMounted] = React.useState(false); | ||
React.useEffect(() => setMounted(true), []); | ||
if (otherProps.value === undefined && otherProps.defaultValue === undefined) { | ||
console.warn( | ||
"SegmentedControl component requires either a `value` or `defaultValue` attribute.", | ||
); | ||
} | ||
|
||
return ( | ||
<div | ||
ref={ref} | ||
{...rootProps} | ||
{...restProps} | ||
{...(!mounted && { style: { display: "flex" } })} | ||
className={clsx(classNames.root, className)} | ||
> | ||
{/* TODO */} | ||
{/* <div {...labelProps} className={classNames.label} /> */} | ||
<SegmentedControlContext.Provider value={{ api }}> | ||
{children} | ||
</SegmentedControlContext.Provider> | ||
<div aria-hidden className={classNames.indicator} {...indicatorProps} /> | ||
</div> | ||
<SeedSegmentedControl.Root ref={ref} {...otherProps}> | ||
{children} | ||
<SeedSegmentedControl.Indicator /> | ||
</SeedSegmentedControl.Root> | ||
); | ||
}); | ||
SegmentedControl.displayName = "SegmentedControl"; | ||
|
||
export interface SegmentProps | ||
extends Assign<React.HTMLAttributes<HTMLLabelElement>, SegmentItemProps> {} | ||
export interface SegmentedControlSegmentProps | ||
extends SeedSegmentedControl.SegmentProps { | ||
inputProps?: React.InputHTMLAttributes<HTMLInputElement>; | ||
|
||
export const Segment = React.forwardRef<HTMLLabelElement, SegmentProps>( | ||
({ className, children, value, ...otherProps }, ref) => { | ||
const { | ||
api: { getSegmentProps }, | ||
} = useSegmentedControlContext(); | ||
rootRef?: React.Ref<HTMLLabelElement>; | ||
} | ||
|
||
const { rootProps, hiddenInputProps, stateProps } = getSegmentProps({ | ||
value, | ||
}); | ||
const classNames = segmentedControl(); | ||
|
||
return ( | ||
<label | ||
ref={ref} | ||
className={clsx(classNames.segment, className)} | ||
{...rootProps} | ||
{...otherProps} | ||
> | ||
<input {...hiddenInputProps} style={visuallyHidden} /> | ||
<div {...stateProps} className={classNames.segmentLabel}> | ||
{children} | ||
</div> | ||
<div aria-hidden className={classNames.segmentLabelPlaceholder}> | ||
{children} | ||
</div> | ||
</label> | ||
); | ||
}, | ||
); | ||
|
||
Segment.displayName = "Segment"; | ||
export const SegmentedControlSegment = React.forwardRef< | ||
HTMLInputElement, | ||
SegmentedControlSegmentProps | ||
>(({ children, inputProps, rootRef, ...otherProps }, ref) => { | ||
return ( | ||
<SeedSegmentedControl.Segment ref={rootRef} {...otherProps}> | ||
<SeedSegmentedControl.SegmentHiddenInput ref={ref} {...inputProps} /> | ||
<SeedSegmentedControl.SegmentLabel> | ||
{children} | ||
</SeedSegmentedControl.SegmentLabel> | ||
<SeedSegmentedControl.SegmentLabelPlaceholder aria-hidden> | ||
{children} | ||
</SeedSegmentedControl.SegmentLabelPlaceholder> | ||
</SeedSegmentedControl.Segment> | ||
); | ||
}); | ||
SegmentedControlSegment.displayName = "SegmentedControlSegment"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.