Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3a6d626
feat: add input segments + time field (#3464)
paulodetarsofm Mar 6, 2024
139bb13
feat(calendar): add calendar component (#3327)
paulodetarsofm Mar 6, 2024
41c1878
refactor: calendar improvements
paulodetarsofm Mar 6, 2024
77079e8
feat(date-time-picker): add input segments + time field (#3464)
paulodetarsofm Aug 23, 2023
3435fb6
refactor: remove time field
paulodetarsofm Nov 29, 2023
d805175
refactor: move locales to be used globally
paulodetarsofm Mar 6, 2024
bdd3272
fix: picker button import
paulodetarsofm Mar 6, 2024
a95fec6
refactor: use `beforeinput` and `input` events
paulodetarsofm Mar 6, 2024
bca1b80
feat: add `date-time-picker` component
paulodetarsofm Mar 6, 2024
78e61c4
fix: use innerText to render segment text
paulodetarsofm Nov 30, 2023
496b975
fix: dealing with days and hours
paulodetarsofm Dec 1, 2023
7127a7e
fix: fix quiet variant styles
Dec 6, 2023
74af9e9
fix: add calculation to count the width of the date/time picker
Dec 7, 2023
7755dd7
refactor: removes solved TODO's points
Dec 7, 2023
97f79ff
refactor: removes broken unit test
Dec 8, 2023
739091c
refactor: adds unit test for default datetime picker
Dec 8, 2023
6aedcfc
refactor: unit tests for date-time-picker
Dec 13, 2023
6873977
refactor: fixes input line height
Dec 19, 2023
148dc83
chore: bump packages to 0.41.2
paulodetarsofm Mar 6, 2024
8e59497
refactor: feedback implementation v1
paulodetarsofm Mar 6, 2024
4254a70
refactor: mock slected date for timeGlanularity story
Dec 21, 2023
5975f88
refactor: adds unit test to calendar
Dec 22, 2023
4ba335c
refactor: update naming
Dec 22, 2023
6a19a69
refactor: adds unit test for handleDayClick method
Dec 22, 2023
0a55f77
refactor: update TODO list
paulodetarsofm Jan 8, 2024
6ebca73
fix: create new segments when granularity is changed
paulodetarsofm Jan 8, 2024
266dfe4
fix: renaming attribute from `locale` to `lang`
paulodetarsofm Jan 11, 2024
4cd79a5
refactor: use "quiet" variant of `sp-picker-button` when input is rea…
paulodetarsofm Jan 12, 2024
97af838
refactor: remove unused imports
paulodetarsofm Jan 12, 2024
9119c5c
refactor: enable "valid" and "invalid" attributes for all stories
paulodetarsofm Jan 12, 2024
1901e55
refactor: italicised placeholders for non-CJK languages
paulodetarsofm Jan 12, 2024
08a748f
refactor: date/time picker width definition
paulodetarsofm Jan 12, 2024
747ec46
chore: bump packages to 0.41.2
paulodetarsofm Mar 6, 2024
e851144
refactor: add comment about use of `.innerText`
paulodetarsofm Jan 15, 2024
6839447
refactor: reduce cognitive complexity
paulodetarsofm Jan 15, 2024
e545b9c
refactor: calendar improvements + unit tests
paulodetarsofm Jan 15, 2024
2060e2d
refactor: invalid picker button styles
paulodetarsofm Jan 17, 2024
2b74de8
chore: bump packages to 0.41.2
paulodetarsofm Mar 6, 2024
c742b9a
refactor: small code improvements
mizgaionutalexandru Jul 17, 2024
597ad3d
chore: fix test imports
mizgaionutalexandru Jul 31, 2024
07a5cba
chore: update golden img hash
mizgaionutalexandru Jul 31, 2024
600c818
chore: update golden img hash
mizgaionutalexandru Jul 31, 2024
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ executors:
parameters:
current_golden_images_hash:
type: string
default: c70f3ed57c4e3536313872fd3d23510caa801a44
default: 07a5cba6726f993d5ddc38a9c30e9c9e3e94ebc7
wireit_cache_name:
type: string
default: wireit
Expand Down
3 changes: 2 additions & 1 deletion packages/calendar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"@spectrum-web-components/reactive-controllers": "^0.41.2"
},
"devDependencies": {
"@spectrum-css/calendar": "^4.2.4"
"@spectrum-css/calendar": "^4.2.4",
"@spectrum-web-components/story-decorator": "^0.41.2"
Copy link
Contributor

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 defaultLocale in prod?

},
"types": "./src/index.d.ts",
"customElements": "custom-elements.json",
Expand Down
9 changes: 7 additions & 2 deletions packages/calendar/src/Calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export class Calendar extends SpectrumElement {
class="spectrum-Calendar-title"
aria-live="assertive"
aria-atomic="true"
data-test-id="calendar-title"
>
${monthAndYear}
</div>
Expand All @@ -176,6 +177,7 @@ export class Calendar extends SpectrumElement {
aria-label="Previous"
title="Previous"
class="spectrum-Calendar-prevMonth"
data-test-id="prev-btn"
?disabled=${this.disabled}
@click=${this.handlePreviousMonth}
>
Expand All @@ -196,6 +198,7 @@ export class Calendar extends SpectrumElement {
aria-label="Next"
title="Next"
class="spectrum-Calendar-nextMonth"
data-test-id="next-btn"
?disabled=${this.disabled}
@click=${this.handleNextMonth}
>
Expand Down Expand Up @@ -311,12 +314,13 @@ export class Calendar extends SpectrumElement {
class="spectrum-Calendar-tableCell"
title=${currentDayTitle}
tabindex=${ifDefined(!isOutsideMonth ? '-1' : undefined)}
aria-disabled=${isOutsideMonth || this.disabled}
aria-disabled=${isOutsideMonth || isDisabled}
aria-selected=${isSelected}
>
<span
role="presentation"
class=${classMap(dayClasses)}
data-test-id="calendar-day"
@click=${() => this.handleDayClick(calendarDate)}
>
${this.formatNumber(calendarDate.day)}
Expand Down Expand Up @@ -361,8 +365,9 @@ export class Calendar extends SpectrumElement {
* defined location (Sunday, Monday, etc.)
*/
private setWeekdays(): void {
const weekStart = startOfWeek(this.currentDate, this.locale);

this.weekdays = [...new Array(daysInWeek).keys()].map((dayIndex) => {
const weekStart = startOfWeek(this.currentDate, this.locale);
const date = weekStart.add({ days: dayIndex });

return {
Expand Down
206 changes: 69 additions & 137 deletions packages/calendar/stories/calendar.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not understandable, can you change it to something like calenderPadding instead

Copy link
Contributor

Choose a reason for hiding this comment

The 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why title is not a part of args?

Copy link
Contributor

@mizgaionutalexandru mizgaionutalexandru Aug 7, 2024

Choose a reason for hiding this comment

The 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
...=${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 => {
Expand Down Expand Up @@ -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,
};
Loading