@servicetitan/docs-anvil-uikit-contrib 32.6.0 → 33.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/intl/API/intlstore.mdx +1 -1
- package/docs/intl/API/use-intl.mdx +1 -1
- package/docs/intl/currency.mdx +8 -0
- package/docs/intl/dates.mdx +20 -10
- package/docs/intl/numbers.mdx +10 -2
- package/docs/intl/plurals.mdx +11 -2
- package/docs/intl/times.mdx +24 -6
- package/docs/testing-library/index.mdx +0 -2
- package/package.json +2 -2
|
@@ -10,7 +10,7 @@ It is preferred to use the [`useIntl` hook](./use-intl.mdx) instead of directly
|
|
|
10
10
|
|
|
11
11
|
## Overview
|
|
12
12
|
|
|
13
|
-
The `IntlStore` is an injectable store that maintains an [`intl`](https://formatjs.github.io/docs/react-intl/api#intlshape) object with the same formatting functions and locale information available through the [`useIntl`](./use-intl.mdx) hook. It extends the standard `react-intl` functionality with custom ServiceTitan formatters. The `IntlStore` is provided by [`
|
|
13
|
+
The `IntlStore` is an injectable store that maintains an [`intl`](https://formatjs.github.io/docs/react-intl/api#intlshape) object with the same formatting functions and locale information available through the [`useIntl`](./use-intl.mdx) hook. It extends the standard `react-intl` functionality with custom ServiceTitan formatters. The `IntlStore` is provided by [`MobxIntlProvider`](./mobx-intl-provider.mdx).
|
|
14
14
|
|
|
15
15
|
## Basic Usage
|
|
16
16
|
|
|
@@ -51,7 +51,7 @@ The [`intl`](https://formatjs.github.io/docs/react-intl/api#intlshape) object re
|
|
|
51
51
|
- [`formatCurrency()`](../currency.mdx) - Format currency
|
|
52
52
|
- [`formatPluralMessage()`](../plurals.mdx#formatpluralmessage) - Provide a number and messages associated with plural forms, and receive the appropriate message for the current locale and plural form
|
|
53
53
|
|
|
54
|
-
###
|
|
54
|
+
### Properties
|
|
55
55
|
|
|
56
56
|
- `currency` - Current currency code (e.g., 'USD')
|
|
57
57
|
- `locale` - Current locale (e.g., 'en-US')
|
package/docs/intl/currency.mdx
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
title: Currency
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import {
|
|
6
|
+
FormattedCurrencyMiniDemo
|
|
7
|
+
} from '@servicetitan/intl/demo';
|
|
8
|
+
import { DemoExample } from '@site/src/components/code-demo';
|
|
5
9
|
import Tabs from '@theme/Tabs';
|
|
6
10
|
|
|
7
11
|
Numbers can be formatted as currency either by using the `FormattedCurrency` component from `@servicetitan/intl`, or via the `formatCurrency()` function as part of the `intl` object, which can be retrieved via the [`useIntl()`](./API/use-intl.mdx) hook or through the [`IntlStore`](./API/intlstore.mdx) store.
|
|
@@ -90,3 +94,7 @@ class CurrencyExampleStore {
|
|
|
90
94
|
### Further customization
|
|
91
95
|
|
|
92
96
|
If you need to customize the formatting further, `FormattedCurrency` and `formatCurrency` accept the same options as the native `Intl.NumberFormat` API, but `style` is always set to `"currency"`, and `currency` defaults to `currency` from the `IntlProvider`/`MobxIntlProvider`. See [`Intl.NumberFormat` for more information about those options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).
|
|
97
|
+
|
|
98
|
+
### Demo
|
|
99
|
+
|
|
100
|
+
<DemoExample example={FormattedCurrencyMiniDemo} />
|
package/docs/intl/dates.mdx
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
title: Dates
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import {
|
|
6
|
+
FormattedDateMiniDemo
|
|
7
|
+
} from '@servicetitan/intl/demo';
|
|
8
|
+
import { DemoExample } from '@site/src/components/code-demo';
|
|
5
9
|
import Tabs from '@theme/Tabs';
|
|
6
10
|
|
|
7
11
|
Dates can be formatted either by using the [`FormattedDate`](#formatteddate) component from `@servicetitan/intl`, or via the [`formatDate`](#formatdate) function as part of the `intl` object, which can be retrieved via the [`useIntl`](./API/use-intl.mdx) hook or through the [`IntlStore`](./API/intlstore.mdx) store.
|
|
@@ -14,8 +18,8 @@ Dates can be formatted either by using the [`FormattedDate`](#formatteddate) com
|
|
|
14
18
|
|
|
15
19
|
The following standard ServiceTitan formats are available to use as part of date formatting. The *short* format is used if none is specified. The formats follow the "Dates and time" section of the ["Style Guide - General guidelines"](https://servicetitan.atlassian.net/wiki/spaces/DTW/pages/262701057/Style+Guide+-+General+guidelines#Dates-and-time).
|
|
16
20
|
|
|
17
|
-
- `short` results in `09/02/
|
|
18
|
-
- `long` results in `September 2, 2025`
|
|
21
|
+
- `short` results in `09/02/2025` for 'en-US' locale (default if no format is specified)
|
|
22
|
+
- `long` results in `September 2, 2025` for 'en-US' locale
|
|
19
23
|
|
|
20
24
|
## Usage
|
|
21
25
|
|
|
@@ -29,8 +33,8 @@ function DateExample() {
|
|
|
29
33
|
|
|
30
34
|
return (
|
|
31
35
|
<div>
|
|
32
|
-
<FormattedDate value={date} /> {/* "09/02/
|
|
33
|
-
<FormattedDate value={date} format="short" /> {/* "09/02/
|
|
36
|
+
<FormattedDate value={date} /> {/* "09/02/2025" */}
|
|
37
|
+
<FormattedDate value={date} format="short" /> {/* "09/02/2025" */}
|
|
34
38
|
<FormattedDate value={date} format="long" /> {/* "September 2, 2025" */}
|
|
35
39
|
</div>
|
|
36
40
|
);
|
|
@@ -53,12 +57,13 @@ import { useIntl } from '@servicetitan/intl';
|
|
|
53
57
|
|
|
54
58
|
function DateExample() {
|
|
55
59
|
const intl = useIntl();
|
|
60
|
+
const date = new Date('2025-09-02');
|
|
56
61
|
|
|
57
62
|
return (
|
|
58
63
|
<>
|
|
59
|
-
{intl.formatDate(
|
|
60
|
-
{intl.formatDate(
|
|
61
|
-
{intl.formatDate(
|
|
64
|
+
{intl.formatDate(date)} {/* "09/02/2025" */}
|
|
65
|
+
{intl.formatDate(date, { format: 'short' })} {/* "09/02/2025" */}
|
|
66
|
+
{intl.formatDate(date, { format: 'long' })} {/* "September 2, 2025" */}
|
|
62
67
|
</>
|
|
63
68
|
);
|
|
64
69
|
}
|
|
@@ -75,10 +80,11 @@ class MyStore {
|
|
|
75
80
|
constructor(@inject(IntlStore) private readonly intlStore: IntlStore) {}
|
|
76
81
|
|
|
77
82
|
formatDate() {
|
|
83
|
+
const date = new Date('2025-09-02');
|
|
78
84
|
return [
|
|
79
|
-
this.intlStore.intl.formatDate(
|
|
80
|
-
this.intlStore.intl.formatDate(
|
|
81
|
-
this.intlStore.intl.formatDate(
|
|
85
|
+
this.intlStore.intl.formatDate(date), // 09/02/2025
|
|
86
|
+
this.intlStore.intl.formatDate(date, { format: 'short' }), // 09/02/2025
|
|
87
|
+
this.intlStore.intl.formatDate(date, { format: 'long' }), // September 2, 2025
|
|
82
88
|
];
|
|
83
89
|
}
|
|
84
90
|
}
|
|
@@ -90,3 +96,7 @@ class MyStore {
|
|
|
90
96
|
### Further customization
|
|
91
97
|
|
|
92
98
|
If you need to customize the formatting further, `FormattedDate` and `formatDate` accept the same options as the native `Intl.DateTimeFormat` API. See [`Intl.DateTimeFormat` for more information about those options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat), and see Format.js [`FormattedDate` documentation](https://formatjs.github.io/docs/react-intl/components/#formatteddate) or [`formatDate` documentation](https://formatjs.github.io/docs/react-intl/api/#formatdate) for more information on how to use them.
|
|
99
|
+
|
|
100
|
+
### Demo
|
|
101
|
+
|
|
102
|
+
<DemoExample example={FormattedDateMiniDemo} />
|
package/docs/intl/numbers.mdx
CHANGED
|
@@ -2,16 +2,20 @@
|
|
|
2
2
|
title: Numbers
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import {
|
|
6
|
+
FormattedNumberMiniDemo
|
|
7
|
+
} from '@servicetitan/intl/demo';
|
|
8
|
+
import { DemoExample } from '@site/src/components/code-demo';
|
|
5
9
|
import Tabs from '@theme/Tabs';
|
|
6
10
|
|
|
7
|
-
Numbers can be formatted either by using the `FormattedNumber` component from
|
|
11
|
+
Numbers can be formatted either by using the `FormattedNumber` component from `@servicetitan/intl`, or via the `formatNumber()` function as part of the `intl` object, which can be retrieved via the [`useIntl()`](./API/use-intl.mdx) hook or through the [`IntlStore`](./API/intlstore.mdx) store.
|
|
8
12
|
|
|
9
13
|
## Usage
|
|
10
14
|
|
|
11
15
|
### FormattedNumber
|
|
12
16
|
|
|
13
17
|
```tsx
|
|
14
|
-
import { FormattedNumber } from '
|
|
18
|
+
import { FormattedNumber } from '@servicetitan/intl';
|
|
15
19
|
|
|
16
20
|
function NumberExample() {
|
|
17
21
|
return (
|
|
@@ -77,3 +81,7 @@ class ReportService {
|
|
|
77
81
|
### Further customization
|
|
78
82
|
|
|
79
83
|
If you need to customize the formatting further, `FormattedNumber` and `formatNumber` accept the same options as the native `Intl.NumberFormat` API. See [`Intl.NumberFormat` for more information about those options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat), and see Format.js [`FormattedNumber` documentation](https://formatjs.github.io/docs/react-intl/components/#formattednumber) or [`formatNumber` documentation](https://formatjs.github.io/docs/react-intl/api/#formatnumber) for more information on how to use them.
|
|
84
|
+
|
|
85
|
+
### Demo
|
|
86
|
+
|
|
87
|
+
<DemoExample example={FormattedNumberMiniDemo} />
|
package/docs/intl/plurals.mdx
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
title: Plurals
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import {
|
|
6
|
+
FormattedPluralMiniDemo
|
|
7
|
+
} from '@servicetitan/intl/demo';
|
|
8
|
+
import { DemoExample } from '@site/src/components/code-demo';
|
|
5
9
|
import Tabs from '@theme/Tabs';
|
|
6
10
|
|
|
7
|
-
Plurals can be formatted by using the `FormattedPlural` component from
|
|
11
|
+
Plurals can be formatted by using the `FormattedPlural` component from `@servicetitan/intl`, or via the `formatPluralMessage()` function as part of the `intl` object, which can be retrieved via the [`useIntl()`](./API/use-intl.mdx) hook or through the [`IntlStore`](./API/intlstore.mdx) store.
|
|
8
12
|
|
|
9
13
|
[`FormattedPlural`](#formattedplural) and [`formatPluralMessage()`](#formatpluralmessage) are only meant to be used with one language. Since ServiceTitan currently only supports English, and [English only uses "one" and "other" forms](https://www.unicode.org/cldr/charts/42/supplemental/language_plural_rules.html#en), those will be the only forms you will use at this time.
|
|
10
14
|
|
|
@@ -19,7 +23,7 @@ When ServiceTitan eventually supports multiple languages, the library will be up
|
|
|
19
23
|
See Format.js [FormattedPlural documentation](https://formatjs.github.io/docs/react-intl/components/#formattedplural) for more information.
|
|
20
24
|
|
|
21
25
|
```tsx
|
|
22
|
-
import { FormattedPlural } from '
|
|
26
|
+
import { FormattedPlural } from '@servicetitan/intl';
|
|
23
27
|
...
|
|
24
28
|
<FormattedPlural value={5} one="item" other="items" />
|
|
25
29
|
```
|
|
@@ -73,3 +77,8 @@ class MyStore {
|
|
|
73
77
|
|
|
74
78
|
</TabItem>
|
|
75
79
|
</Tabs>
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### Demo
|
|
83
|
+
|
|
84
|
+
<DemoExample example={FormattedPluralMiniDemo} />
|
package/docs/intl/times.mdx
CHANGED
|
@@ -2,32 +2,46 @@
|
|
|
2
2
|
title: Times
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import {
|
|
6
|
+
FormattedTimeMiniDemo
|
|
7
|
+
} from '@servicetitan/intl/demo';
|
|
8
|
+
import { DemoExample } from '@site/src/components/code-demo';
|
|
5
9
|
import Tabs from '@theme/Tabs';
|
|
6
10
|
|
|
7
|
-
Times can be formatted either by using the [`FormattedTime`](#formattedtime) component from
|
|
11
|
+
Times can be formatted either by using the [`FormattedTime`](#formattedtime) component from `@servicetitan/intl`, or via the [`formatTime`](#formattime) function as part of the `intl` object, which can be retrieved via the [`useIntl`](./API/use-intl.mdx) hook or through the [`IntlStore`](./API/intlstore.mdx) store.
|
|
8
12
|
|
|
9
13
|
## Available Formats
|
|
10
14
|
|
|
11
|
-
The following standard ServiceTitan formats are available to use as part of time formatting. The
|
|
15
|
+
The following standard ServiceTitan formats are available to use as part of time formatting. The **short** format is used if none is specified. The formats follow the "Date and time" section of the [Anvil2 Content documentation](https://anvil.servicetitan.com/web/content/date-and-time).
|
|
16
|
+
|
|
17
|
+
:::note
|
|
18
|
+
The example results that follow use a locale of 'en-US' and time zone of 'America/New_York'
|
|
19
|
+
:::
|
|
12
20
|
|
|
13
21
|
- `short` results in `4:00 PM` (default if no format is specified)
|
|
22
|
+
- `shortTimezone` results in `4:00 PM EDT`
|
|
23
|
+
- `utc` results in `08:00 PM UTC` (forces UTC timezone and adds leading zero)
|
|
14
24
|
- `medium` results in `4:00:00 PM`
|
|
25
|
+
- `mediumTimeZone` results in `4:00:00 PM EDT`
|
|
15
26
|
|
|
16
27
|
## Usage
|
|
17
28
|
|
|
18
29
|
### FormattedTime
|
|
19
30
|
|
|
20
31
|
```tsx
|
|
21
|
-
import { FormattedTime } from '
|
|
32
|
+
import { FormattedTime } from '@servicetitan/intl';
|
|
22
33
|
|
|
23
34
|
function TimeExample() {
|
|
24
|
-
const time = new Date();
|
|
35
|
+
const time = new Date('2025-09-02 16:00:00');
|
|
25
36
|
|
|
26
37
|
return (
|
|
27
38
|
<>
|
|
28
39
|
<FormattedTime value={time} /> {/* "4:00 PM" */}
|
|
29
40
|
<FormattedTime value={time} format="short" /> {/* "4:00 PM" */}
|
|
41
|
+
<FormattedTime value={time} format="shortTimeZone" /> {/* "4:00 PM EDT" */}
|
|
42
|
+
<FormattedTime value={time} format="utc" /> {/* "08:00 PM" UTC*/}
|
|
30
43
|
<FormattedTime value={time} format="medium" /> {/* "4:00:00 PM" */}
|
|
44
|
+
<FormattedTime value={time} format="mediumTimeZone" /> {/* "4:00:00 PM EDT" */}
|
|
31
45
|
</>
|
|
32
46
|
);
|
|
33
47
|
}
|
|
@@ -49,7 +63,7 @@ import { useIntl } from '@servicetitan/intl';
|
|
|
49
63
|
|
|
50
64
|
function TimeExample() {
|
|
51
65
|
const intl = useIntl();
|
|
52
|
-
const time = new Date();
|
|
66
|
+
const time = new Date('2025-09-02 16:00:00');
|
|
53
67
|
|
|
54
68
|
return (
|
|
55
69
|
<>
|
|
@@ -74,7 +88,7 @@ class ScheduleService {
|
|
|
74
88
|
|
|
75
89
|
formatTime() {
|
|
76
90
|
const intl = this.intlStore.intl;
|
|
77
|
-
const time = new Date();
|
|
91
|
+
const time = new Date('2025-09-02 16:00:00');
|
|
78
92
|
|
|
79
93
|
return [
|
|
80
94
|
intl.formatTime(time), // "4:00 PM"
|
|
@@ -91,3 +105,7 @@ class ScheduleService {
|
|
|
91
105
|
### Further customization
|
|
92
106
|
|
|
93
107
|
If you need to customize the formatting further, `FormattedTime` and `formatTime` accept the same options as the native `Intl.DateTimeFormat` API. See [`Intl.DateTimeFormat` for more information about those options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat), and see Format.js [`FormattedTime` documentation](https://formatjs.github.io/docs/react-intl/components/#formattedtime) or [`formatTime` documentation](https://formatjs.github.io/docs/react-intl/api/#formattime) for more information on how to use them.
|
|
108
|
+
|
|
109
|
+
### Demo
|
|
110
|
+
|
|
111
|
+
<DemoExample example={FormattedTimeMiniDemo} />
|
|
@@ -18,5 +18,3 @@ This library has `peerDependencies` for:
|
|
|
18
18
|
- `@testing-library/react`: >=12.0.0
|
|
19
19
|
- `@testing-library/react-hooks`: >=7.0.0 (only if using `@testing-library/react` v12)
|
|
20
20
|
- `react`: >=17.0.0
|
|
21
|
-
|
|
22
|
-
**Note:** This library is not compatible with React Testing Library versions 13+.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/docs-anvil-uikit-contrib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "33.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
"cli": {
|
|
17
17
|
"webpack": false
|
|
18
18
|
},
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "73576ba8cbadb851c04aacc9c2fd295be3678d29"
|
|
20
20
|
}
|