@vygruppen/spor-react 2.3.0 → 2.3.3
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +20 -0
- package/dist/{CountryCodeSelect-B2GP2C3U.mjs → CountryCodeSelect-WGG2Z3VI.mjs} +1 -1
- package/dist/{chunk-NYC3Z75S.mjs → chunk-QXVLVC2K.mjs} +296 -276
- package/dist/index.d.ts +78 -19
- package/dist/index.js +404 -382
- package/dist/index.mjs +1 -1
- package/package.json +6 -7
- package/src/i18n/index.tsx +100 -9
- package/src/input/{Counter.tsx → NumericStepper.tsx} +13 -10
- package/src/input/index.tsx +1 -1
- package/src/provider/SporProvider.tsx +1 -1
package/dist/index.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, Badge, Box, Button, ButtonGroup, Card, CardSelect, Center, Checkbox, CheckboxGroup, ChoiceChip, ClosableAlert, CloseButton, Code, Collapse, ColorInlineLoader, ColorSpinner, Container, ContentLoader,
|
1
|
+
export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, Badge, Box, Button, ButtonGroup, Card, CardSelect, Center, Checkbox, CheckboxGroup, ChoiceChip, ClosableAlert, CloseButton, Code, Collapse, ColorInlineLoader, ColorSpinner, Container, ContentLoader, DarkFullScreenLoader, DarkInlineLoader, DarkMode, DarkSpinner, DatePicker, DateRangePicker, Divider, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, ModalHeader as DrawerHeader, DrawerOverlay, Expandable, ExpandableAlert, ExpandableItem, Fade, Flex, FloatingActionButton, FormControl, FormErrorMessage, FormHelperText, FormLabel, Grid, GridItem, HStack, Heading, IconButton, Image, Img, InfoSelect, InfoTag, Input, InputGroup, InputLeftElement, InputRightElement, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightMode, LightSpinner, LineIcon, ListBox, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, NativeSelect, NumericStepper, PasswordInput, PhoneNumberInput, PlayPauseButton, Popover, PopoverAnchor, PopoverArrow, PopoverBody, PopoverCloseButton, PopoverContent, PopoverFooter, PopoverHeader, PopoverTrigger, PopoverWizardBody, ProgressBar, ProgressLoader, Radio, RadioGroup, ScaleFade, SearchInput, Item as SelectItem, SelectItemDescription, SelectItemLabel, SimpleDrawer, SimpleGrid, SimplePopover, Skeleton, SkeletonCircle, SkeletonText, SkipButton, Slide, SlideFade, Spacer, SporProvider, Stack, StaticAlert, Stepper, StepperStep, Switch, Tab, TabList, TabPanel, TabPanels, Table, TableCaption, Tabs, Tbody, Td, Text, TextLink, Textarea, Tfoot, Th, Thead, Time, TimePicker, Tr, TravelTag, VStack, VyLogo, WizardPopover, Wrap, WrapItem, createTexts, extendTheme, fontFaces, theme, tokens, useBreakpointValue, useClipboard, useColorMode, useColorModePreference, useColorModeValue, useControllableProp, useDisclosure, useMediaQuery, useMergeRefs, useOutsideClick, usePrefersReducedMotion, useTheme, useToast, useToken, useTranslation } from './chunk-QXVLVC2K.mjs';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vygruppen/spor-react",
|
3
|
-
"version": "2.3.
|
3
|
+
"version": "2.3.3",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"types": "./dist/index.d.ts",
|
@@ -17,15 +17,14 @@
|
|
17
17
|
"directory": "packages/spor-react"
|
18
18
|
},
|
19
19
|
"dependencies": {
|
20
|
-
"@chakra-ui/react": "^2.
|
20
|
+
"@chakra-ui/react": "^2.6.1",
|
21
21
|
"@chakra-ui/theme-tools": "^2.0.12",
|
22
|
+
"@emotion/react": "^11.10.4",
|
23
|
+
"@emotion/styled": "^11.10.4",
|
22
24
|
"@internationalized/date": "^3.0.1",
|
23
|
-
"@leile/lobo-t": "^1.0.5",
|
24
25
|
"@vygruppen/spor-design-tokens": "*",
|
25
26
|
"@vygruppen/spor-icon-react": "*",
|
26
27
|
"@vygruppen/spor-loader": "*",
|
27
|
-
"@emotion/react": "^11.10.4",
|
28
|
-
"@emotion/styled": "^11.10.4",
|
29
28
|
"framer-motion": ">6.0.0",
|
30
29
|
"lottie-react": "^2.3.1",
|
31
30
|
"react-aria": "^3.23.0",
|
@@ -33,10 +32,10 @@
|
|
33
32
|
"react-swipeable": "^7.0.0"
|
34
33
|
},
|
35
34
|
"devDependencies": {
|
36
|
-
"react": "^18.2.0",
|
37
|
-
"react-dom": "^18.2.0",
|
38
35
|
"@testing-library/jest-dom": "^5.16.5",
|
39
36
|
"@testing-library/react": "^13.4.0",
|
37
|
+
"react": "^18.2.0",
|
38
|
+
"react-dom": "^18.2.0",
|
40
39
|
"tsup": "^6.2.2",
|
41
40
|
"vitest": "^0.26.3",
|
42
41
|
"vitest-axe": "^0.1.0",
|
package/src/i18n/index.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import React, { createContext, useContext } from "react";
|
2
2
|
|
3
3
|
export enum Language {
|
4
4
|
NorwegianBokmal = "nb",
|
@@ -7,18 +7,101 @@ export enum Language {
|
|
7
7
|
English = "en",
|
8
8
|
}
|
9
9
|
|
10
|
-
|
11
|
-
Language.
|
12
|
-
);
|
13
|
-
|
14
|
-
type LanguageObject = {
|
15
|
-
[key in Language]: string;
|
10
|
+
type TranslationObject = {
|
11
|
+
[key in Language]: string | React.ReactElement;
|
16
12
|
};
|
17
|
-
type
|
13
|
+
type TranslationFunction = (
|
14
|
+
...args: Array<string | number>
|
15
|
+
) => TranslationObject;
|
18
16
|
|
17
|
+
type Translation = TranslationObject | TranslationFunction;
|
19
18
|
export type Translations = {
|
20
|
-
[key: string]:
|
19
|
+
[key: string]: Translation | Translations;
|
20
|
+
};
|
21
|
+
|
22
|
+
const LanguageContext = createContext<Language | undefined>(undefined);
|
23
|
+
type LanguageProviderProps = {
|
24
|
+
language: Language;
|
25
|
+
children: React.ReactElement;
|
21
26
|
};
|
27
|
+
/**
|
28
|
+
* A language provider component.
|
29
|
+
*
|
30
|
+
* This component should wrap your entire application. It will provide the language to all components that use it.
|
31
|
+
*
|
32
|
+
* This is done by the SporProvider component, so most likely, you won't need to use it directly, unless you want to use a specific language for a specific part of your application.
|
33
|
+
*
|
34
|
+
* ```tsx
|
35
|
+
* import { LanguageProvider, Language } from "@vygruppen/spor-react";
|
36
|
+
*
|
37
|
+
* const App = () => {
|
38
|
+
* return (
|
39
|
+
* <LanguageProvider language={Language.NorwegianBokmal}>
|
40
|
+
* <Routes />
|
41
|
+
* </LanguageProvider>
|
42
|
+
* );
|
43
|
+
* }
|
44
|
+
* ```
|
45
|
+
*
|
46
|
+
*/
|
47
|
+
export function LanguageProvider({
|
48
|
+
language,
|
49
|
+
children,
|
50
|
+
}: LanguageProviderProps) {
|
51
|
+
return (
|
52
|
+
<LanguageContext.Provider value={language}>
|
53
|
+
{children}
|
54
|
+
</LanguageContext.Provider>
|
55
|
+
);
|
56
|
+
}
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Gets the language from the language context.
|
60
|
+
*
|
61
|
+
* @internal
|
62
|
+
*/
|
63
|
+
function useLanguage() {
|
64
|
+
const language = useContext(LanguageContext);
|
65
|
+
if (!language) {
|
66
|
+
throw new Error("Please wrap your application in a LanguageProvider");
|
67
|
+
}
|
68
|
+
return language;
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* A hook that returns translation utilities. Typically used to translate text.
|
73
|
+
*
|
74
|
+
* ```tsx
|
75
|
+
* const Example = () => {
|
76
|
+
* const { t } = useTranslation();
|
77
|
+
* return <p>{t(texts.greeting)}</p>;
|
78
|
+
* }
|
79
|
+
* const texts = {
|
80
|
+
* greeting: {
|
81
|
+
* nb: "Hei",
|
82
|
+
* nn: "Hei",
|
83
|
+
* sv: "Hej",
|
84
|
+
* en: "Hello",
|
85
|
+
* }
|
86
|
+
* }
|
87
|
+
* ```
|
88
|
+
*
|
89
|
+
* You can also use it to fetch the current language:
|
90
|
+
*
|
91
|
+
* ```tsx
|
92
|
+
* const Example = () => {
|
93
|
+
* const { language } = useTranslation();
|
94
|
+
* return <p>{language}</p>;
|
95
|
+
* };
|
96
|
+
* ```
|
97
|
+
*/
|
98
|
+
export function useTranslation() {
|
99
|
+
const language = useLanguage();
|
100
|
+
const t = (text: TranslationObject) => {
|
101
|
+
return text[language] as string;
|
102
|
+
};
|
103
|
+
return { t, language } as const;
|
104
|
+
}
|
22
105
|
|
23
106
|
/** Utility function that creates type safe text objects with useTranslation
|
24
107
|
*
|
@@ -29,6 +112,14 @@ export type Translations = {
|
|
29
112
|
* nn: "Døme",
|
30
113
|
* sv: "Exempel",
|
31
114
|
* en: "Example",
|
115
|
+
* },
|
116
|
+
* another: {
|
117
|
+
* example: {
|
118
|
+
* nb: <strong>Eksempel</strong>,
|
119
|
+
* nn: <strong>Døme</strong>,
|
120
|
+
* sv: <strong>Exempel</strong>,
|
121
|
+
* en: <strong>Example</strong>,
|
122
|
+
* }
|
32
123
|
* }
|
33
124
|
* })
|
34
125
|
* ```
|
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
import { getBoxShadowString } from "../theme/utils/box-shadow-utils";
|
17
17
|
import { focusVisible } from "../theme/utils/focus-utils";
|
18
18
|
|
19
|
-
type
|
19
|
+
type NumericStepperProps = {
|
20
20
|
/** The name of the input field */
|
21
21
|
name?: string;
|
22
22
|
/** The current value */
|
@@ -29,34 +29,34 @@ type CounterProps = {
|
|
29
29
|
minValue?: number;
|
30
30
|
/** Optional maximum value. Defaults to 99 */
|
31
31
|
maxValue?: number;
|
32
|
-
/** Whether the
|
32
|
+
/** Whether the stepper is disabled or not */
|
33
33
|
isDisabled?: boolean;
|
34
34
|
} & BoxProps;
|
35
|
-
/** A simple
|
35
|
+
/** A simple stepper component for integer values
|
36
36
|
*
|
37
37
|
* Allows you to choose a given integer value, like for example the number of
|
38
38
|
* adults on your journey.
|
39
39
|
*
|
40
40
|
* ```tsx
|
41
|
-
* <
|
41
|
+
* <NumericStepper value={value} onChange={setValue} />
|
42
42
|
* ```
|
43
43
|
*
|
44
44
|
* You can also set a minimum and/or maximum value:
|
45
45
|
*
|
46
46
|
* ```tsx
|
47
|
-
* <
|
47
|
+
* <NumericStepper value={value} onChange={setValue} minValue={1} maxValue={10} />
|
48
48
|
* ```
|
49
49
|
*
|
50
|
-
* You can use the
|
50
|
+
* You can use the NumericStepper inside of a FormControl component to get IDs etc linked up automatically:
|
51
51
|
*
|
52
52
|
* ```tsx
|
53
53
|
* <FormControl>
|
54
54
|
* <FormLabel>Number of adults</FormLabel>
|
55
|
-
* <
|
55
|
+
* <NumericStepper />
|
56
56
|
* </FormControl>
|
57
57
|
* ```
|
58
58
|
*/
|
59
|
-
export function
|
59
|
+
export function NumericStepper({
|
60
60
|
name: nameProp,
|
61
61
|
id: idProp,
|
62
62
|
value: valueProp,
|
@@ -66,7 +66,7 @@ export function Counter({
|
|
66
66
|
maxValue = 99,
|
67
67
|
isDisabled,
|
68
68
|
...boxProps
|
69
|
-
}:
|
69
|
+
}: NumericStepperProps) {
|
70
70
|
const { t } = useTranslation();
|
71
71
|
const [value, onChange] = useControllableState<number>({
|
72
72
|
value: valueProp,
|
@@ -103,7 +103,10 @@ export function Counter({
|
|
103
103
|
textAlign="center"
|
104
104
|
backgroundColor={backgroundColor}
|
105
105
|
color={textColor}
|
106
|
-
transition="
|
106
|
+
transition="box-shadow .1s ease-out"
|
107
|
+
visibility={value === 0 ? "hidden" : "visible"}
|
108
|
+
aria-live="assertive"
|
109
|
+
aria-label={value.toString()}
|
107
110
|
_hover={{
|
108
111
|
boxShadow: getBoxShadowString({
|
109
112
|
borderColor: "currentColor",
|
package/src/input/index.tsx
CHANGED
@@ -5,7 +5,7 @@ export * from "./CardSelect";
|
|
5
5
|
export * from "./Checkbox";
|
6
6
|
export * from "./CheckboxGroup";
|
7
7
|
export * from "./ChoiceChip";
|
8
|
-
export * from "./
|
8
|
+
export * from "./NumericStepper";
|
9
9
|
export * from "./FormControl";
|
10
10
|
export * from "./FormErrorMessage";
|
11
11
|
export * from "./FormLabel";
|