-
Notifications
You must be signed in to change notification settings - Fork 235
feat(date-time-picker): add date/time input + picker #3856
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
Changes from all commits
3a6d626
139bb13
41c1878
77079e8
3435fb6
d805175
bdd3272
a95fec6
bca1b80
78e61c4
496b975
7127a7e
74af9e9
7755dd7
97f79ff
739091c
6aedcfc
6873977
148dc83
8e59497
4254a70
5975f88
4ba335c
6a19a69
0a55f77
6ebca73
266dfe4
4cd79a5
97af838
9119c5c
1901e55
08a748f
747ec46
e851144
6839447
e545b9c
2060e2d
2b74de8
c742b9a
597ad3d
07a5cba
600c818
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,177 +9,71 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA | |
| OF ANY KIND, either express or implied. See the License for the specific language | ||
| governing permissions and limitations under the License. | ||
| */ | ||
| import { html, TemplateResult } from '@spectrum-web-components/base'; | ||
| import { ifDefined } from '@spectrum-web-components/base/src/directives.js'; | ||
| import { html, render, TemplateResult } from '@spectrum-web-components/base'; | ||
| import { defaultLocale } from '@spectrum-web-components/story-decorator/src/StoryDecorator.js'; | ||
|
|
||
| import { spreadProps } from '../../../test/lit-helpers.js'; | ||
|
|
||
| import '@spectrum-web-components/calendar/sp-calendar.js'; | ||
| import '@spectrum-web-components/theme/sp-theme.js'; | ||
|
|
||
| const locales = [ | ||
| 'cs-CZ', | ||
| 'cy-GB', | ||
| 'da-DK', | ||
| 'de-DE', | ||
| 'en-GB', | ||
| 'en-US', | ||
| 'es-ES', | ||
| 'fi-FI', | ||
| 'fr-FR', | ||
| 'hu-HU', | ||
| 'it-IT', | ||
| 'ja-JP', | ||
| 'ko-KR', | ||
| 'nb-NO', | ||
| 'nl-NL', | ||
| 'pl-PL', | ||
| 'pt-BR', | ||
| 'ru-RU', | ||
| 'sv-SE', | ||
| 'tr-TR', | ||
| 'uk-UA', | ||
| 'zh-Hans-CN', | ||
| 'zh-Hans-CN-u-nu-hanidec', | ||
| 'zh-Hant-TW', | ||
| 'zz-ZY', | ||
| 'zz-ZZ', | ||
| ] as const; | ||
|
|
||
| const defaultLocale = 'en-US'; | ||
|
|
||
| const hiddenProperty = { | ||
| table: { | ||
| disable: true, | ||
| }, | ||
| }; | ||
|
|
||
| export default { | ||
| title: 'Calendar', | ||
| component: 'sp-calendar', | ||
|
|
||
| argTypes: { | ||
| lang: { | ||
| options: locales, | ||
| control: { | ||
| type: 'select', | ||
| }, | ||
| table: { | ||
| defaultValue: { | ||
| summary: defaultLocale, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| // Don't render private properties and getters in the Storybook UI | ||
| currentDate: { ...hiddenProperty }, | ||
| minDate: { ...hiddenProperty }, | ||
| maxDate: { ...hiddenProperty }, | ||
| weeksInCurrentMonth: { ...hiddenProperty }, | ||
| weekdays: { ...hiddenProperty }, | ||
| languageResolver: { ...hiddenProperty }, | ||
| timeZone: { ...hiddenProperty }, | ||
| locale: { ...hiddenProperty }, | ||
| today: { ...hiddenProperty }, | ||
|
|
||
| // Inherited | ||
| _dirParent: { ...hiddenProperty }, | ||
| shadowRoot: { ...hiddenProperty }, | ||
| dir: { ...hiddenProperty }, | ||
| isLTR: { ...hiddenProperty }, | ||
| }, | ||
|
|
||
| args: { | ||
| lang: defaultLocale, | ||
| }, | ||
|
|
||
| parameters: { | ||
| controls: { | ||
| // Hide "This story is not configured to handle controls" warning | ||
| hideNoControlsWarning: true, | ||
| }, | ||
| actions: { | ||
| handles: ['onChange'], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| interface StoryArgs { | ||
| lang?: string; | ||
|
|
||
| padded?: boolean; | ||
| disabled?: boolean; | ||
| type ComponentArgs = { | ||
| selectedDate?: Date; | ||
| min?: Date; | ||
| max?: Date; | ||
| padded?: boolean; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not understandable, can you change it to something like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is one of the component's attributes, I think we should stick to this name as the RFC decided. |
||
| disabled?: boolean; | ||
| }; | ||
|
|
||
| onChange?: (date: Date) => void; | ||
| type StoryArgs = ComponentArgs & { | ||
| onChange?: (dateTime: Date) => void; | ||
| }; | ||
|
|
||
| interface SpreadStoryArgs { | ||
| [prop: string]: unknown; | ||
| } | ||
|
|
||
| const renderCalendar = ( | ||
| title: string, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why title is not a part of args?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what was meant here was to distinguish between the component attributes/properties and the h1 used in each story. I will address this in a future PR. |
||
| args: StoryArgs = {} | ||
| ): TemplateResult => { | ||
| return html` | ||
| <sp-theme lang=${ifDefined(args.lang || undefined)}> | ||
| <h1>${title}</h1> | ||
| <h2> | ||
| Locale: | ||
| <code>${args.lang}</code> | ||
| </h2> | ||
|
|
||
| <hr /> | ||
|
|
||
| <sp-calendar | ||
| ...=${spreadProps(args)} | ||
| @change=${args.onChange} | ||
| ></sp-calendar> | ||
| </sp-theme> | ||
| const story = html` | ||
| <h1>${title}</h1> | ||
| <hr /> | ||
| <sp-calendar | ||
mirekszot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ...=${spreadProps(args as SpreadStoryArgs)} | ||
| @change=${args.onChange} | ||
| ></sp-calendar> | ||
| `; | ||
| }; | ||
|
|
||
| export const Default = (args: StoryArgs = {}): TemplateResult => { | ||
| return renderCalendar('Default', args); | ||
| }; | ||
| const randomId = Math.floor(Math.random() * 99999); | ||
|
|
||
| export const padded = (args: StoryArgs = {}): TemplateResult => { | ||
| return renderCalendar(`Padded? ${args.padded}`, args); | ||
| }; | ||
|
|
||
| padded.argTypes = { | ||
| padded: { | ||
| control: 'boolean', | ||
| table: { | ||
| defaultValue: { | ||
| summary: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| padded.args = { | ||
| padded: true, | ||
| }; | ||
| requestAnimationFrame(() => { | ||
| const container = document.querySelector( | ||
| `.story-container-${randomId}` | ||
| ); | ||
|
|
||
| export const disabled = (args: StoryArgs = {}): TemplateResult => { | ||
| return renderCalendar(`Disabled? ${args.disabled}`, args); | ||
| }; | ||
| if (container) { | ||
| render(story, container as HTMLElement); | ||
| } | ||
| }); | ||
|
|
||
| disabled.argTypes = { | ||
| disabled: { | ||
| control: 'boolean', | ||
| table: { | ||
| defaultValue: { | ||
| summary: true, | ||
| }, | ||
| }, | ||
| }, | ||
| return html` | ||
| <div class="story-container-${randomId}"></div> | ||
| `; | ||
| }; | ||
|
|
||
| disabled.args = { | ||
| disabled: true, | ||
| export const Default = (args: StoryArgs = {}): TemplateResult => { | ||
| return renderCalendar('Default', args); | ||
| }; | ||
|
|
||
| export const selectedDate = (args: StoryArgs = {}): TemplateResult => { | ||
|
|
@@ -241,3 +135,41 @@ export const maximumDate = (args: StoryArgs = {}): TemplateResult => { | |
|
|
||
| return renderCalendar(`Maximum Date: ${formatted}`, args); | ||
| }; | ||
|
|
||
| export const disabled = (args: StoryArgs = {}): TemplateResult => { | ||
| return renderCalendar(`Disabled? ${args.disabled}`, args); | ||
| }; | ||
|
|
||
| disabled.argTypes = { | ||
| disabled: { | ||
| control: 'boolean', | ||
| table: { | ||
| defaultValue: { | ||
| summary: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| disabled.args = { | ||
| disabled: true, | ||
| }; | ||
|
|
||
| export const padded = (args: StoryArgs = {}): TemplateResult => { | ||
| return renderCalendar(`Padded? ${args.padded}`, args); | ||
| }; | ||
|
|
||
| padded.argTypes = { | ||
| padded: { | ||
| control: 'boolean', | ||
| table: { | ||
| defaultValue: { | ||
| summary: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| padded.args = { | ||
| padded: true, | ||
| }; | ||
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.
I think this should be in dependencies and not in devDependencies. Do yo not need
defaultLocalein prod?