Skip to content

Commit

Permalink
feat: action prop in Item component
Browse files Browse the repository at this point in the history
Will run after Item selected.

BREAKING CHANGE: Picker will no longer close by default after you
select a day item, you need to set `action="close"` in Item component
  • Loading branch information
aliakbarazizi committed Oct 13, 2023
1 parent 6b5123e commit a1784d9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
44 changes: 44 additions & 0 deletions src/components/datepicker/item/Item.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Item } from './Item';

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction
const meta = {
title: 'Datepicker/Item',
component: Item,
tags: ['autodocs'],
argTypes: {
as: {
table: {
defaultValue: {
summary: 'div',
},
},
},
},
parameters: {
showDatepicker: true,
},
} satisfies Meta<typeof Item>;

export default meta;
type Story = StoryObj<typeof meta>;

export const DateItem = {
parameters: {
override: {
item: `{item}`,
},
},
args: {
item: {
type: 'day',
disabled: false,
isSelected: false,
isHeader: false,
isToday: false,
key: 0,
text: '1',
value: new Date(),
},
},
} satisfies Story;
9 changes: 6 additions & 3 deletions src/components/datepicker/item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { Props } from '../../../type';
import { forwardRef, render } from '../../../utils/render';
import { PickerContext } from '../picker/Picker';
import { ButtonProps } from '..';

const DEFAULT_TAG = 'button';

Expand All @@ -19,12 +20,14 @@ export type ItemProps<
ElemenElementTag,
DatepickerSlot,
typeof itemDataAttribute,
{ item: DateItemType | HourItemType }
{
item: DateItemType | HourItemType;
} & Partial<Pick<ButtonProps, 'action'>>
>;

export const Item = forwardRef(
<ElemenElementTag extends ElementType>(
{ item, ...props }: ItemProps<ElemenElementTag>,
{ item, action, ...props }: ItemProps<ElemenElementTag>,
ref: Ref<HTMLElement>,
) => {
const { id } = useContext(PickerContext);
Expand All @@ -39,7 +42,7 @@ export const Item = forwardRef(
: () => {
dispatch({
type: 'select',
payload: { item, pickerId: id },
payload: { item, pickerId: id, action },
});
},
};
Expand Down

0 comments on commit a1784d9

Please sign in to comment.