Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Picker 컴포넌트 QA사항 반영 #154

Merged
merged 7 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fresh-dodos-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wowds-ui": patch
---

Picker 컴포넌트와 DropDownOption 컴포넌트를 수정합니다.
22 changes: 15 additions & 7 deletions packages/wow-ui/src/components/DropDown/DropDownOption.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client";

import { cva } from "@styled-system/css";
import { cva, cx } from "@styled-system/css";
import { styled } from "@styled-system/jsx";
import type { ReactNode } from "react";
import type { CSSProperties, ReactNode } from "react";
import { forwardRef, useCallback, useEffect } from "react";

import { useDropDownContext } from "@/components/DropDown/context/DropDownContext";
Expand All @@ -14,16 +14,20 @@ import { useCollection } from "./context/CollectionContext";
*
* @param {string} value 옵션의 값입니다.
* @param {() => void} [onClick] 옵션이 클릭되었을 때 호출되는 함수입니다.
* @param {React.ReactNode} [text] 드롭다운 옵션에 들어갈 텍스트.
* @param {React.ReactNode} text 드롭다운 옵션에 들어갈 텍스트.
* @param {CSSProperties} [style] 드롭다운 옵션의 커스텀 스타일.
* @param {string} [className] 드롭다운 옵션에 전달하는 커스텀 클래스.
*/
export interface DropDownOptionProps {
value: string;
onClick?: () => void;
text: ReactNode;
style?: CSSProperties;
className?: string;
}

const DropDownOption = forwardRef<HTMLLIElement, DropDownOptionProps>(
function Option({ value, onClick, text }, ref) {
function Option({ value, onClick, text, className, ...rest }, ref) {
const { focusedValue, selectedValue, handleSelect, dropdownId } =
useDropDownContext();
const isSelected = selectedValue === value;
Expand Down Expand Up @@ -52,12 +56,16 @@ const DropDownOption = forwardRef<HTMLLIElement, DropDownOptionProps>(
ref={ref}
role="option"
tabIndex={isSelected ? 0 : -1}
className={optionStyle({
type: isSelected ? "selected" : isFocused ? "focused" : "default",
})}
className={cx(
optionStyle({
type: isSelected ? "selected" : isFocused ? "focused" : "default",
}),
className
)}
onClick={() => {
handleOptionClick(value, onClick);
}}
{...rest}
>
{text}
</styled.li>
Expand Down
14 changes: 14 additions & 0 deletions packages/wow-ui/src/components/Picker/DatePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,17 @@ export const TimeRange = () => {
</Flex>
);
};

export const DisabledDatePicker = () => {
const [selected, setSelected] = useState<Date | undefined>(new Date());

return (
<PickerGroup selectedDate={selected} setSelectedDate={setSelected}>
<DatePicker
disabled={{ from: new Date("2024-09-04"), to: new Date("2024-09-05") }}
label="종료 날짜"
/>
<TimePicker disabled label="종료 시간" />
</PickerGroup>
);
};
4 changes: 2 additions & 2 deletions packages/wow-ui/src/components/Picker/PickerGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const PickerGroup = ({
setSelectedDate,
label,
}: PickerGroupProps) => {
const hours = selectedDate?.getHours() || 12;
const hours = selectedDate?.getHours();
const [time, setTime] = useState<Time>({
isAM: selectedDate ? hours < 12 : true,
isAM: selectedDate && hours ? hours < 12 : true,
hour: selectedDate && hours && hours !== 12 ? hours % 12 : 12,
minute: selectedDate ? selectedDate.getMinutes() : 0,
});
Expand Down
24 changes: 20 additions & 4 deletions packages/wow-ui/src/components/Picker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ interface TimePickerProps
Pick<PickerContextProps, "selectedTime" | "setSelectedTime">
> {
label?: string;
disabled?: boolean;
}

const TimePicker = forwardRef<HTMLDivElement, TimePickerProps>(
(
{
label,
disabled,
selectedTime: propSelectedTime,
setSelectedTime: propSetSelectedTime,
},
Expand Down Expand Up @@ -52,7 +54,11 @@ const TimePicker = forwardRef<HTMLDivElement, TimePickerProps>(
const strTime = formatTimeToString(selectedTime);

return (
<Flex direction="column" gap="0.75rem">
<Flex
direction="column"
gap="0.75rem"
pointerEvents={disabled ? "none" : "auto"}
>
{label && (
<styled.span color="sub" textStyle="label2">
{label}
Expand All @@ -62,7 +68,7 @@ const TimePicker = forwardRef<HTMLDivElement, TimePickerProps>(
<button
className={pickerButtonStyle({
variant: "time",
state: selected ? "selected" : "default",
state: disabled ? "disabled" : selected ? "selected" : "default",
})}
onClick={handleClickAMOrPM}
>
Expand All @@ -73,7 +79,11 @@ const TimePicker = forwardRef<HTMLDivElement, TimePickerProps>(
<button
className={pickerButtonStyle({
variant: "time",
state: selected ? "selected" : "default",
state: disabled
? "disabled"
: selected
? "selected"
: "default",
})}
>
{strTime.hour}
Expand All @@ -84,6 +94,7 @@ const TimePicker = forwardRef<HTMLDivElement, TimePickerProps>(
{hours.map((hour) => (
<DropDownOption
key={hour}
style={{ padding: "0.25rem 0.5rem", textAlign: "center" }}
text={hour.padStart(2, "0")}
value={hour}
/>
Expand All @@ -94,7 +105,11 @@ const TimePicker = forwardRef<HTMLDivElement, TimePickerProps>(
<button
className={pickerButtonStyle({
variant: "time",
state: selected ? "selected" : "default",
state: disabled
? "disabled"
: selected
? "selected"
: "default",
})}
>
{strTime.minute}
Expand All @@ -105,6 +120,7 @@ const TimePicker = forwardRef<HTMLDivElement, TimePickerProps>(
{minutes.map((minute) => (
<DropDownOption
key={minute}
style={{ padding: "0.25rem 0.5rem", textAlign: "center" }}
text={minute.padStart(2, "0")}
value={minute}
/>
Expand Down
10 changes: 10 additions & 0 deletions packages/wow-ui/src/components/Picker/pickerButtonStyle.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,15 @@ export const pickerButtonStyle = cva({
},
},
},
{
variant: "time",
state: "disabled",
css: {
background: "monoBackgroundPressed",
color: "outline",

borderWidth: 0,
},
},
],
});
4 changes: 4 additions & 0 deletions packages/wow-ui/src/components/Picker/pickerClassNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const pickerClassNames: Partial<ClassNames> | undefined = {
width: "100%",
}),
weekday: pickerButtonStyle({ variant: "date", state: "default" }),
disabled: pickerButtonStyle({
variant: "date",
state: "disabled",
}),
day: pickerButtonStyle({ variant: "date", state: "default" }),
day_button: css({
width: "100%",
Expand Down
Loading