-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: S2 DateField/DatePicker/Calendar #8428
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
Open
snowystinger
wants to merge
36
commits into
main
Choose a base branch
from
s2-datepicker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
c143634
feat: S2 DateField/DatePicker/Calendar
snowystinger 3b4f669
fix lint
snowystinger 6401de3
start calendar
snowystinger 7bbdd47
Style calendar and fix some datepicker styles
snowystinger 0716d72
changing ring size
snowystinger b67342f
fix hover
snowystinger beb5265
revert outline size change
snowystinger fb693ab
add range calendar
snowystinger 1ab4699
fix yarn lock
snowystinger f51db9c
fix cell styles for different size ring and gap
snowystinger b1d5752
Merge branch 'main' into s2-datepicker
snowystinger c8e2ef2
add spectrum context
snowystinger eb5c4ff
Add DateRangePicker
snowystinger aa71a83
add comment
snowystinger 8b864c3
fix test
snowystinger 0cbd107
Add TimeField and aria labels
snowystinger 559c1bc
add press scaling
snowystinger 0f697a8
Merge branch 'main' into s2-datepicker
snowystinger 90332c7
fix non-contiguous ranges styles
snowystinger 6fbf922
fix lint
snowystinger a82e047
remove explicit modules
snowystinger 3db69f6
Merge branch 'main' into s2-datepicker
snowystinger 356148a
Add time fields to date pickers
snowystinger b0f6cac
fix buttons in date picker popover
snowystinger eb9685a
remove console log
snowystinger 6da6c82
fix storybook intermittent crash from implicit actions, scrolling
snowystinger 5ee804b
fix accessibility violation
snowystinger f065877
review changes and deduplicating code
snowystinger d17b7fd
make outline in range smaller
snowystinger be9560f
Label instead of aria label the stories by default
snowystinger 3450170
reduce duplication, fix styles
snowystinger aa7701d
remove added api for day/week index and add storybook decorators for …
snowystinger 27c4230
field widths, share more
snowystinger 33628a0
Add hcm support
snowystinger fad7550
add chromatic stories and fix bugs
snowystinger 6ee3dc6
remove problematic story
snowystinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
131 changes: 131 additions & 0 deletions
131
packages/@react-spectrum/s2/chromatic/Calendar.stories.tsx
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright 2024 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
import {Calendar} from '../src'; | ||
import {CalendarDate} from '@internationalized/date'; | ||
import {Custom454Calendar} from '../../../@internationalized/date/tests/customCalendarImpl'; | ||
import {DateValue} from 'react-aria'; | ||
import type {Meta, StoryObj} from '@storybook/react'; | ||
import {screen, userEvent, within} from '@storybook/test'; | ||
|
||
const meta: Meta<typeof Calendar> = { | ||
component: Calendar, | ||
parameters: { | ||
chromaticProvider: {disableAnimations: true} | ||
}, | ||
title: 'S2 Chromatic/Calendar' | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Calendar>; | ||
|
||
const date = new CalendarDate(2022, 2, 3); | ||
|
||
export const Default: Story = { | ||
args: { | ||
defaultFocusedValue: date | ||
} | ||
}; | ||
|
||
export const MultiMonth: Story = { | ||
args: { | ||
defaultFocusedValue: date, | ||
visibleMonths: 3 | ||
} | ||
}; | ||
|
||
export const UnavailableDays: Story = { | ||
args: { | ||
defaultFocusedValue: date, | ||
minValue: new CalendarDate(2022, 2, 2), | ||
maxValue: new CalendarDate(2022, 2, 20), | ||
isDateUnavailable: (date: DateValue) => { | ||
return date.day >= 15 && date.day <= 18; | ||
}, | ||
isInvalid: true, | ||
errorMessage: 'Invalid date' | ||
} | ||
}; | ||
|
||
export const CustomCalendar: Story = { | ||
args: { | ||
defaultFocusedValue: date, | ||
createCalendar: () => new Custom454Calendar() | ||
}, | ||
parameters: { | ||
chromaticProvider: { | ||
// only works for en-US? | ||
locales: ['en-US'] | ||
} | ||
} | ||
}; | ||
|
||
export const DefaultHover: Story = { | ||
args: { | ||
defaultFocusedValue: date | ||
}, | ||
play: async () => { | ||
let grid = screen.getByRole('grid'); | ||
let cell = within(grid).getAllByRole('button')[7]; | ||
await userEvent.hover(cell); | ||
}, | ||
parameters: { | ||
chromaticProvider: { | ||
colorSchemes: ['light'], | ||
backgrounds: ['base'], | ||
locales: ['en-US'], | ||
disableAnimations: true | ||
} | ||
} | ||
}; | ||
|
||
export const DefaultKeyboardFocus: Story = { | ||
args: { | ||
defaultFocusedValue: date | ||
}, | ||
play: async () => { | ||
await userEvent.tab(); | ||
await userEvent.tab(); | ||
await userEvent.tab(); | ||
await userEvent.keyboard('{ArrowDown}'); | ||
}, | ||
parameters: { | ||
chromaticProvider: { | ||
colorSchemes: ['light'], | ||
backgrounds: ['base'], | ||
locales: ['en-US'], | ||
disableAnimations: true | ||
} | ||
} | ||
}; | ||
|
||
export const DefaultKeyboardSelected: Story = { | ||
args: { | ||
defaultFocusedValue: date | ||
}, | ||
play: async () => { | ||
await userEvent.tab(); | ||
await userEvent.tab(); | ||
await userEvent.tab(); | ||
await userEvent.keyboard('{ArrowDown}'); | ||
await userEvent.keyboard('{Enter}'); | ||
}, | ||
parameters: { | ||
chromaticProvider: { | ||
colorSchemes: ['light'], | ||
backgrounds: ['base'], | ||
locales: ['en-US'], | ||
disableAnimations: true | ||
} | ||
} | ||
}; |
62 changes: 62 additions & 0 deletions
62
packages/@react-spectrum/s2/chromatic/DateField.stories.tsx
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2024 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
import {CalendarDate} from '@internationalized/date'; | ||
import {DateField} from '../'; | ||
import type {Meta, StoryObj} from '@storybook/react'; | ||
import {userEvent} from '@storybook/test'; | ||
|
||
const meta: Meta<typeof DateField> = { | ||
component: DateField, | ||
parameters: { | ||
chromaticProvider: {disableAnimations: true} | ||
}, | ||
title: 'S2 Chromatic/DateField' | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof DateField>; | ||
|
||
const date = new CalendarDate(2022, 2, 3); | ||
|
||
export const Default: Story = { | ||
args: { | ||
label: 'Date of birth' | ||
} | ||
}; | ||
|
||
export const WithValue: Story = { | ||
args: { | ||
label: 'Date of birth', | ||
value: date | ||
} | ||
}; | ||
|
||
export const Focused: Story = { | ||
args: { | ||
label: 'Date of birth', | ||
value: date | ||
}, | ||
play: async () => { | ||
await userEvent.tab(); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
}, | ||
parameters: { | ||
chromaticProvider: { | ||
colorSchemes: ['light'], | ||
backgrounds: ['base'], | ||
locales: ['en-US'], | ||
disableAnimations: true | ||
} | ||
} | ||
}; |
111 changes: 111 additions & 0 deletions
111
packages/@react-spectrum/s2/chromatic/DatePicker.stories.tsx
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright 2024 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
import {CalendarDate, CalendarDateTime} from '@internationalized/date'; | ||
import {DatePicker} from '../'; | ||
import type {Meta, StoryObj} from '@storybook/react'; | ||
import {userEvent} from '@storybook/test'; | ||
|
||
const meta: Meta<typeof DatePicker> = { | ||
component: DatePicker, | ||
parameters: { | ||
chromaticProvider: {disableAnimations: true} | ||
}, | ||
title: 'S2 Chromatic/DatePicker' | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof DatePicker>; | ||
|
||
const date = new CalendarDate(2022, 2, 3); | ||
|
||
export const Default: Story = { | ||
args: { | ||
label: 'Date of birth' | ||
} | ||
}; | ||
|
||
export const WithValue: Story = { | ||
args: { | ||
label: 'Date of birth', | ||
value: date | ||
} | ||
}; | ||
|
||
export const Focused: Story = { | ||
args: { | ||
label: 'Date of birth', | ||
value: date | ||
}, | ||
play: async () => { | ||
await userEvent.tab(); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
}, | ||
parameters: { | ||
chromaticProvider: { | ||
colorSchemes: ['light'], | ||
backgrounds: ['base'], | ||
locales: ['en-US'], | ||
disableAnimations: true | ||
} | ||
} | ||
}; | ||
|
||
export const OpenPicker: Story = { | ||
args: { | ||
label: 'Date of birth', | ||
value: date | ||
}, | ||
play: async () => { | ||
await userEvent.tab(); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
await userEvent.keyboard('{Enter}'); | ||
}, | ||
parameters: { | ||
chromaticProvider: { | ||
colorSchemes: ['light'], | ||
backgrounds: ['base'], | ||
locales: ['en-US'], | ||
disableAnimations: true | ||
} | ||
} | ||
}; | ||
|
||
export const OpenPickerWithTime: Story = { | ||
args: { | ||
label: 'Date of birth', | ||
value: new CalendarDateTime(2022, 2, 3, 12, 0, 0), | ||
granularity: 'second' | ||
}, | ||
play: async () => { | ||
await userEvent.tab(); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
await userEvent.keyboard('{Enter}'); | ||
}, | ||
parameters: { | ||
chromaticProvider: { | ||
colorSchemes: ['light'], | ||
backgrounds: ['base'], | ||
locales: ['en-US'], | ||
disableAnimations: true | ||
} | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another way to do this? see RangeCalendar implementation for use