@vygruppen/spor-react 2.3.1 → 2.3.4
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 +9 -9
- package/CHANGELOG.md +20 -0
- package/dist/{CountryCodeSelect-ZOSDJ6DE.mjs → CountryCodeSelect-WGG2Z3VI.mjs} +1 -1
- package/dist/{chunk-DSLSJDMJ.mjs → chunk-QXVLVC2K.mjs} +293 -273
- package/dist/index.d.ts +71 -12
- package/dist/index.js +399 -377
- package/dist/index.mjs +1 -1
- package/package.json +6 -7
- package/src/i18n/index.tsx +100 -9
- package/src/input/NumericStepper.tsx +5 -2
- package/src/input/PhoneNumberInput.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, 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-
|
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.4",
|
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
|
* ```
|
@@ -31,7 +31,7 @@ type NumericStepperProps = {
|
|
31
31
|
maxValue?: number;
|
32
32
|
/** Whether the stepper is disabled or not */
|
33
33
|
isDisabled?: boolean;
|
34
|
-
} & BoxProps
|
34
|
+
} & Omit<BoxProps, "onChange">;
|
35
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
|
@@ -103,7 +103,10 @@ export function NumericStepper({
|
|
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",
|
@@ -12,7 +12,7 @@ type CountryCodeAndPhoneNumber = {
|
|
12
12
|
countryCode: string;
|
13
13
|
nationalNumber: string;
|
14
14
|
};
|
15
|
-
type PhoneNumberInputProps = BoxProps & {
|
15
|
+
type PhoneNumberInputProps = Omit<BoxProps, "onChange"> & {
|
16
16
|
/** The root name.
|
17
17
|
*
|
18
18
|
* Please note that when specifying the name, the rendered names will be `${name}-country-code` and `${name}-phone-number`, respectively
|