1.1.2 • Published 29 days ago

@equinor/fusion-wc-date v1.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
29 days ago

fusion-wc-date Published on npm

Storybook

Installation

npm install @equinor/fusion-wc-date

DateTime <fwc-datetime>

Example Usage

Date

return (
  <fwc-datetime format={DateTimeFormat.date} date='2021-08-09T11:12:49Z' />
);

Date & Time

return (
  <fwc-datetime format={DateTimeFormat.datetime} date='2021-08-09T11:12:49Z' />
);

Time

return (
  <fwc-datetime format={DateTimeFormat.time} date='2021-08-09T11:12:49Z' />
);

Custom

return (
  <fwc-datetime format='yyyy.MM.dd' date='2021-08-09T11:12:49Z' />
);

Alternative format type

The format variable can also be given as a value instead of a typed enum

return (
  <fwc-datetime format='datetime' date='2021-08-09T11:12:49Z' />
);

With custom locale property

return (
  <fwc-datetime format={DateTimeFormat.time} date='2021-08-09T11:12:49Z' locale='nb' />
);

Properties/Attributes

NameTypeDefaultDescription
datestringcurrent dateThe date to format in ISO format. See 'ISO_8601'.
formatDateTimeFormat* or stringdatetimePredefined or custom format to use. Based on Unicode Technical Standard #35.
localeLocaleName**enGBUsed to override the locale for which the date format is based. See date-fns Locale.

* DateTimeFormat is exported by fwc-date.

enum DateTimeFormat {
  date='dd.MM.yyyy',
  time='HH:mm',
  datetime='HH:mm dd.MM.yyyy',
  time_with_seconds='HH:mm:ss',
  datetime_with_seconds='HH:mm:ss dd.MM.yyyy',
}

** LocaleName is exported by fwc-date. See date-fns Locale for all supported locales.

type LocaleName = 'enGB' | 'enUS' | 'nb' | ...;

Range <fwc-daterange>

Example Usage

Relative

return (
  <fwc-daterange variant='relative' date='2021-08-09T09:12:49Z' baseDate='2021-08-09T11:12:49Z' />
);

Distance

return (
  <fwc-daterange variant='distance' date='2021-08-09T09:12:49Z' baseDate='2021-08-09T11:12:49Z' />
);

Date & Time (From - To)

return (
  <fwc-daterange
    variant='datetime'
    format={DateTimeFormat.datetime}
    date='2021-08-09T09:12:49Z'
    baseDate='2021-08-09T11:12:49Z'
  />
);

Date & Time with custom separator

return (
  <fwc-daterange
    variant='datetime'
    format={DateTimeFormat.datetime}
    date='2021-08-09T09:12:49Z'
    baseDate='2021-08-09T11:12:49Z'
  >
  <span slot='separator'>to</span>
  </fwc-daterange>
);

With custom locale property

return (
  <fwc-daterange
    variant='datetime'
    format={DateTimeFormat.datetime}
    date='2021-08-09T09:12:49Z'
    baseDate='2021-08-09T11:12:49Z'
    locale='nb'
  >
  <span slot='separator'>to</span>
  </fwc-daterange>
);

Slots

NameDefaultDescription
separator<span>-</span>Separator element to render between from and to dates for variant datetime.

Properties/Attributes

NameTypeDefaultDescription
fromstringcurrent dateThe date to format in ISO format. See 'ISO_8601'.
tostringcurrent dateThe date to compare with in ISO format. See 'ISO_8601'.
variantDateRangeVariant*datetimeTemplated variant to use as basis for format calculation, defaults to datetime (HH:mm dd.MM.yyyy - HH:mm dd.MM.yyyy).
formatDateTimeFormat** or stringundefinedPredefined or custom format to use. Based on Unicode Technical Standard #35.
localeLocaleName***enGBUsed to override the locale for which the date format is based. See date-fns Locale.
secondsbooleanfalseSet true to include seconds in the distance variant.
weekstartWeekDay****1The index of the first day of the week (0 = Sunday).
suffixbooleanfalseInclude a suffix to indicate if the date is before or after the baseDate. Only applies to variant distance.
capitalizebooleanfalseSet true to capitalize the first character in the formatted text. Applies to distance and relative variants.

* DateRangeVariant is exported by fwc-date.

type DateRangeVariant = 'relative' | 'distance' | 'datetime';

** DateTimeFormat is exported by fwc-date.

enum DateTimeFormat {
  date = 'dd.MM.yyyy',
  time = 'HH:mm',
  datetime = 'HH:mm dd.MM.yyyy',
  time_with_seconds = 'HH:mm:ss',
  datetime_with_seconds = 'HH:mm:ss dd.MM.yyyy',
}

*** LocaleName is exported by fwc-date. See date-fns Locale for all supported locales.

type LocaleName = 'enGB' | 'enUS' | 'nb' | ...;

**** WeekDay is exported by fwc-date.

type WeekDay = 0 | 1 | 2 | 3 | 4 | 5 | 6;
1.1.2

29 days ago

1.1.1

2 months ago

1.1.0

6 months ago

1.0.1

6 months ago

1.0.0

8 months ago

0.2.28-next.1

8 months ago

0.2.28-next.0

8 months ago

0.2.29

8 months ago

0.2.28

8 months ago

0.2.27

11 months ago

0.2.26

1 year ago

0.2.25

1 year ago

0.2.24

1 year ago

0.2.23

2 years ago

0.2.22

2 years ago

0.2.16

2 years ago

0.2.21

2 years ago

0.2.20

2 years ago

0.2.19

2 years ago

0.2.18

2 years ago

0.2.17

2 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.3

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago