Skip to content

Commit

Permalink
feat: props update
Browse files Browse the repository at this point in the history
  • Loading branch information
LLmoskk committed Dec 10, 2024
1 parent 8a5d758 commit 0e99eaa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const MyComponent = () => {
<TimePeriodSelector
title='Select Time Period'
language='en'
weekDayStyle={{ color: 'blue' }}
showTime
className='time-period-selector'
/>
</div>
Expand All @@ -31,12 +31,12 @@ const MyComponent = () => {

## Props

| Name | Type | Description |
| ---- | ---- | ----------- |
| title | string | The title of the component |
| language | 'zh','en' | The language of the component |
| weekDayStyle | React.CSSProperties | The style of the week day |
| className | string | The class name of the component |
| Name | Type | Description |
| --------- | ------------------- | ------------------------------- |
| title | string | The title of the component |
| language | 'zh','en' | The language of the component |
| showTime | boolean | Whether to show time |
| className | string | The class name of the component |

## Component Features

Expand All @@ -49,10 +49,11 @@ const MyComponent = () => {
The TimePeriodSelector component uses weekDays as the list of days in a week and renders the selection area for each day based on this list. Each day's selected time periods (Time type) are stored as an array of numbers representing the selected time range.

```tsx
const weekDays: readonly ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
const weekDays: readonly ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
type WeekDay = (typeof weekDays)[number];
export type Time = Record<WeekDay, number[]>;
```

## License
MIT License

MIT License
24 changes: 15 additions & 9 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export interface TimePeriodSelectorProps {
style?: React.CSSProperties;
title?: string;
language?: 'zh' | 'en';
weekDayStyle?: React.CSSProperties;
};
showTime?: boolean;
}

export function TimePeriodSelector(props: TimePeriodSelectorProps) {
const { className, style, title, language = 'en', weekDayStyle } = props;
const { className, style, title, language = 'en', showTime } = props;
const weekDayDisplay =
language === 'en' ? weekDayDisplayEn : weekDayDisplayZh;

Expand Down Expand Up @@ -221,12 +221,18 @@ export function TimePeriodSelector(props: TimePeriodSelectorProps) {
</tbody>
</table>

<div className='mb-5 mt-5 border-b border-gray-200' />

<div className='mb-2'>
{language === 'zh' ? '已选择时间:' : 'Selected Times:'}
</div>
<pre className='whitespace-pre-wrap text-xs '>{formatSelectedTimes()}</pre>
{showTime && (
<>
<div className='mb-5 mt-5 border-b border-gray-200' />

<div className='mb-2'>
{language === 'zh' ? '已选择时间:' : 'Selected Times:'}
</div>
<pre className='whitespace-pre-wrap text-xs '>
{formatSelectedTimes()}
</pre>
</>
)}
</div>
);
}

0 comments on commit 0e99eaa

Please sign in to comment.