@northlight/ui 1.4.1 → 1.4.2

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.
@@ -1,4 +1,5 @@
1
- import { ComponentType } from 'react';
1
+ import { ComponentType, ReactNode } from 'react';
2
+ import { RouteComponentProps } from 'react-router-dom';
2
3
 
3
4
  type DefaultComponent = {
4
5
  default: ComponentType<any>;
@@ -12,10 +13,51 @@ interface MainPage extends Page {
12
13
  Icon: any;
13
14
  subItems?: Page[];
14
15
  }
16
+ interface SearchBarComponentsBarProps {
17
+ routes: Page[];
18
+ }
19
+ interface RouteOption {
20
+ label: string;
21
+ value: string;
22
+ }
23
+
24
+ interface RoutingProps {
25
+ routes: MainPage[];
26
+ basename?: string;
27
+ fallback?: string;
28
+ }
29
+ declare const Routing: ({ routes, basename, fallback }: RoutingProps) => JSX.Element;
30
+
31
+ type LazyPageProps = {
32
+ loader: () => Promise<DefaultComponent>;
33
+ children?: (component: ComponentType<any>, props: RouteComponentProps) => ReactNode;
34
+ } & RouteComponentProps;
35
+ declare const LazyPage: ({ loader, children, ...rest }: LazyPageProps) => JSX.Element;
36
+
37
+ interface MenuItemProps {
38
+ path: string;
39
+ title: string;
40
+ Icon: any;
41
+ }
42
+ interface MainMenuProps {
43
+ menuItems: MenuItemProps[];
44
+ }
45
+ declare const MainMenu: ({ menuItems }: MainMenuProps) => JSX.Element;
46
+
47
+ interface SubMenuItemProps {
48
+ path: string;
49
+ title: string;
50
+ }
51
+ interface SubMenuProps {
52
+ mainRoutes: MainPage[];
53
+ }
54
+ declare const SubMenu: ({ mainRoutes }: SubMenuProps) => JSX.Element;
55
+
56
+ declare const SearchComponentsBar: ({ routes, }: SearchBarComponentsBarProps) => JSX.Element | null;
15
57
 
16
58
  interface SandboxProps {
17
59
  routes: MainPage[];
18
60
  }
19
61
  declare const Sandbox: ({ routes }: SandboxProps) => JSX.Element;
20
62
 
21
- export { Sandbox };
63
+ export { DefaultComponent, LazyPage, LazyPageProps, MainMenu, MainMenuProps, MainPage, MenuItemProps, Page, RouteOption, Routing, Sandbox, SandboxProps, SearchBarComponentsBarProps, SearchComponentsBar, SubMenu, SubMenuItemProps };
@@ -1,10 +1,10 @@
1
- import React, { forwardRef as forwardRef$1, useImperativeHandle, useRef, useEffect, cloneElement, createContext, memo, useState, useMemo, useContext, Suspense } from 'react';
2
- import { Switch as Switch$3, Route, Redirect, NavLink, useLocation, useHistory, BrowserRouter, Link as Link$2 } from 'react-router-dom';
3
- import { ifElse, gt, always, identity, forEach, is, trim, keys, values, equals, last, map, prop, difference, times, merge, filter, test, toLower, head } from 'ramda';
1
+ import React, { useMemo, Suspense, forwardRef as forwardRef$1, useImperativeHandle, useRef, useEffect, cloneElement, createContext, memo, useState, useContext } from 'react';
2
+ import { Switch as Switch$2, Route, Redirect, NavLink, useLocation, useHistory, BrowserRouter, Link as Link$2 } from 'react-router-dom';
3
+ import { forwardRef, useStyleConfig, Icon as Icon$2, Text, FormLabel as FormLabel$1, VisuallyHidden, Box, Button as Button$2, IconButton as IconButton$1, useMultiStyleConfig, chakra, Table, Thead, Tbody, Tr, Tag as Tag$2, TagLabel, TagRightIcon, useEditableControls, useEditableState, HStack, Editable, InputGroup, InputLeftElement, Input as Input$1, EditablePreview, EditableInput, InputRightElement, Modal as Modal$2, ModalOverlay, ModalContent, ModalCloseButton, ModalHeader, ModalBody, Stack, Slider, SliderTrack, SliderFilledTrack, SliderThumb, ModalFooter, keyframes, useToken as useToken$1, extendTheme, ChakraProvider, Switch as Switch$3, useDisclosure, Card, Grid, Flex, Link as Link$1, FormControl } from '@chakra-ui/react';
4
4
  import { CheckDuo, SearchDuo, DotsMatrixSolid, XCloseSolid, EditDuo, ZoomInDuo, ArrowCircleRightDuo, NorthlightLogoXs } from '@northlight/icons';
5
- import { forwardRef, useStyleConfig, Icon as Icon$2, Text, FormLabel as FormLabel$1, VisuallyHidden, Box, Button as Button$2, IconButton as IconButton$1, useMultiStyleConfig, chakra, Table, Thead, Tbody, Tr, Tag as Tag$2, TagLabel, TagRightIcon, useEditableControls, useEditableState, HStack, Editable, InputGroup, InputLeftElement, Input as Input$1, EditablePreview, EditableInput, InputRightElement, Modal as Modal$2, ModalOverlay, ModalContent, ModalCloseButton, ModalHeader, ModalBody, Stack, Slider, SliderTrack, SliderFilledTrack, SliderThumb, ModalFooter, keyframes, useToken as useToken$1, extendTheme, ChakraProvider, Switch as Switch$2, useDisclosure, Card, Grid, Flex, Link as Link$1, FormControl } from '@chakra-ui/react';
6
5
  import { useToken, useMultiStyleConfig as useMultiStyleConfig$1, chakra as chakra$1 } from '@chakra-ui/system';
7
6
  import { palette, WebappSkin as WebappSkin$1, typography, TottSkin as TottSkin$1, coreZIndex, coreSizing, coreSpacing, coreFontWeight, coreBoxShadow, coreFontSize, coreLineHeight, coreBorderRadius } from '@northlight/tokens';
7
+ import { ifElse, gt, always, identity, forEach, is, trim, keys, values, equals, last, map, prop, difference, times, merge, filter, test, toLower, head } from 'ramda';
8
8
  import { useForm, FormProvider } from 'react-hook-form';
9
9
  import { useFocusManager } from '@react-aria/focus';
10
10
  import '@react-aria/checkbox';
@@ -32,8 +32,54 @@ import AutoSizer from 'react-virtualized-auto-sizer';
32
32
  import AvatarEditor from 'react-avatar-editor';
33
33
  import { randomColor } from '@chakra-ui/theme-tools';
34
34
  import 'react-input-mask';
35
- import { I18nManager, I18nContext } from '@shopify/react-i18n';
36
35
  import Fuse from 'fuse.js';
36
+ import { I18nManager, I18nContext } from '@shopify/react-i18n';
37
+
38
+ const LazyPage = ({ loader, children, ...rest }) => {
39
+ const Component = useMemo(() => React.lazy(loader), []);
40
+ return /* @__PURE__ */ React.createElement(Suspense, { fallback: /* @__PURE__ */ React.createElement("p", null, "Loading....") }, children ? children(Component, { ...rest }) : /* @__PURE__ */ React.createElement(Component, { ...rest }));
41
+ };
42
+
43
+ const normalizePath = ({
44
+ basename,
45
+ path
46
+ }) => basename ? `${basename}${path}` : path;
47
+ const Routing = ({ routes, basename, fallback }) => /* @__PURE__ */ React.createElement(Switch$2, null, routes.flatMap(({ path, component, subItems = [] }) => {
48
+ const routePath = normalizePath({ basename, path });
49
+ const mainRoute = /* @__PURE__ */ React.createElement(
50
+ Route,
51
+ {
52
+ key: routePath,
53
+ exact: true,
54
+ path: routePath,
55
+ render: (props) => /* @__PURE__ */ React.createElement(
56
+ LazyPage,
57
+ {
58
+ ...props,
59
+ loader: component
60
+ }
61
+ )
62
+ }
63
+ );
64
+ const subRoutes = subItems.map(({ path: subPath, component: subComponent }) => {
65
+ const fullPath = `${path}${subPath}`;
66
+ return /* @__PURE__ */ React.createElement(
67
+ Route,
68
+ {
69
+ key: fullPath,
70
+ path: fullPath,
71
+ render: (props) => /* @__PURE__ */ React.createElement(
72
+ LazyPage,
73
+ {
74
+ ...props,
75
+ loader: subComponent
76
+ }
77
+ )
78
+ }
79
+ );
80
+ });
81
+ return [mainRoute, ...subRoutes];
82
+ }), fallback && /* @__PURE__ */ React.createElement(Redirect, { to: fallback }));
37
83
 
38
84
  const Icon$1 = forwardRef(({
39
85
  as: As,
@@ -3292,7 +3338,7 @@ const Switch = ({
3292
3338
  size = "md",
3293
3339
  ...rest
3294
3340
  }) => /* @__PURE__ */ React.createElement(
3295
- Switch$2,
3341
+ Switch$3,
3296
3342
  {
3297
3343
  size,
3298
3344
  id: name,
@@ -3314,137 +3360,6 @@ forwardRef((props, ref) => {
3314
3360
  );
3315
3361
  });
3316
3362
 
3317
- const users = {
3318
- "obi-wan": {
3319
- name: "Obi-Wan Kenobi",
3320
- country: "Germany",
3321
- image: `
3322
- https://www.gamereactor.se/media/08/redaxresonerar_3470803.jpg
3323
- `,
3324
- preferences: {
3325
- locale: "de-DE",
3326
- currency: "EUR",
3327
- firstDayOfWeek: "monday"
3328
- }
3329
- },
3330
- anakin: {
3331
- name: "Anakin Skywalker",
3332
- country: "US",
3333
- image: `
3334
- https://thenerdstash.com/wp-content/uploads/2021/10/Hayden-Christensen-Anakin-Skywalker.jpg
3335
- `,
3336
- preferences: {
3337
- locale: "en-US",
3338
- currency: "USD",
3339
- firstDayOfWeek: "sunday"
3340
- }
3341
- },
3342
- han: {
3343
- name: "Han Solo",
3344
- country: "Sweden",
3345
- image: `
3346
- https://fictionhorizon.com/wp-content/uploads/2021/09/Han-Solo.jpg
3347
- `,
3348
- preferences: {
3349
- locale: "sv-SE",
3350
- currency: "SEK",
3351
- firstDayOfWeek: "sunday"
3352
- }
3353
- },
3354
- yoda: {
3355
- name: "Yoda",
3356
- country: "England",
3357
- image: `
3358
- https://markerasomolast.files.wordpress.com/2013/08/yoda.jpg
3359
- `,
3360
- preferences: {
3361
- locale: "en-GB",
3362
- currency: "GBP",
3363
- firstDayOfWeek: "monday"
3364
- }
3365
- }
3366
- };
3367
- const UserContext = createContext(null);
3368
- const UserProvider = ({ children }) => {
3369
- const [user, setUser] = useState(users["obi-wan"]);
3370
- const contextValue = useMemo(() => ({
3371
- user,
3372
- setUser
3373
- }), [user]);
3374
- return /* @__PURE__ */ React.createElement(UserContext.Provider, { value: contextValue }, children);
3375
- };
3376
- const useUser = () => {
3377
- const context = useContext(UserContext);
3378
- if (!context) {
3379
- throw new Error("Cannot find <UserProvider> anywhere in your React tree");
3380
- }
3381
- return context;
3382
- };
3383
-
3384
- const I18nProvider = ({ children }) => {
3385
- const { user } = useUser();
3386
- const i18nManager = useMemo(() => {
3387
- const { preferences: { locale, currency } } = user;
3388
- return new I18nManager({
3389
- locale,
3390
- currency
3391
- });
3392
- }, [user]);
3393
- return /* @__PURE__ */ React.createElement(I18nContext.Provider, { value: i18nManager }, children);
3394
- };
3395
-
3396
- const CalendarProvider = ({ children }) => {
3397
- const { user: { preferences: { firstDayOfWeek = "monday" } } } = useUser();
3398
- const calendarLocale = firstDayOfWeek === "monday" ? "en-GB" : "en-US";
3399
- return /* @__PURE__ */ React.createElement(I18nProvider$1, { locale: calendarLocale }, children);
3400
- };
3401
-
3402
- const LazyPage = ({ loader, children, ...rest }) => {
3403
- const Component = useMemo(() => React.lazy(loader), []);
3404
- return /* @__PURE__ */ React.createElement(Suspense, { fallback: /* @__PURE__ */ React.createElement("p", null, "Loading....") }, children ? children(Component, { ...rest }) : /* @__PURE__ */ React.createElement(Component, { ...rest }));
3405
- };
3406
-
3407
- const normalizePath = ({
3408
- basename,
3409
- path
3410
- }) => basename ? `${basename}${path}` : path;
3411
- const Routing = ({ routes, basename, fallback }) => /* @__PURE__ */ React.createElement(Switch$3, null, routes.flatMap(({ path, component, subItems = [] }) => {
3412
- const routePath = normalizePath({ basename, path });
3413
- const mainRoute = /* @__PURE__ */ React.createElement(
3414
- Route,
3415
- {
3416
- key: routePath,
3417
- exact: true,
3418
- path: routePath,
3419
- render: (props) => /* @__PURE__ */ React.createElement(
3420
- LazyPage,
3421
- {
3422
- ...props,
3423
- loader: component
3424
- }
3425
- )
3426
- }
3427
- );
3428
- const subRoutes = subItems.map(({ path: subPath, component: subComponent }) => {
3429
- const fullPath = `${path}${subPath}`;
3430
- return /* @__PURE__ */ React.createElement(
3431
- Route,
3432
- {
3433
- key: fullPath,
3434
- path: fullPath,
3435
- render: (props) => /* @__PURE__ */ React.createElement(
3436
- LazyPage,
3437
- {
3438
- ...props,
3439
- loader: subComponent
3440
- }
3441
- )
3442
- }
3443
- );
3444
- });
3445
- return [mainRoute, ...subRoutes];
3446
- }), fallback && /* @__PURE__ */ React.createElement(Redirect, { to: fallback }));
3447
-
3448
3363
  const MenuItem = ({ path, Icon: IconComponent, title }) => /* @__PURE__ */ React.createElement(
3449
3364
  HStack,
3450
3365
  {
@@ -3482,7 +3397,7 @@ const SubMenu = ({ mainRoutes }) => /* @__PURE__ */ React.createElement(
3482
3397
  bgColor: "background.default",
3483
3398
  sx: { "::-webkit-scrollbar": { display: "none" }, "::-webkit-scrollbar-thumb": { background: "blue.500" }, _hover: { "::-webkit-scrollbar": { display: "block" } } }
3484
3399
  },
3485
- /* @__PURE__ */ React.createElement(Switch$3, null, mainRoutes.map(({ path: mainPath, subItems = [] }) => /* @__PURE__ */ React.createElement(
3400
+ /* @__PURE__ */ React.createElement(Switch$2, null, mainRoutes.map(({ path: mainPath, subItems = [] }) => /* @__PURE__ */ React.createElement(
3486
3401
  Route,
3487
3402
  {
3488
3403
  key: mainPath,
@@ -3630,6 +3545,91 @@ const SearchComponentsBar = ({
3630
3545
  ));
3631
3546
  };
3632
3547
 
3548
+ const users = {
3549
+ "obi-wan": {
3550
+ name: "Obi-Wan Kenobi",
3551
+ country: "Germany",
3552
+ image: `
3553
+ https://www.gamereactor.se/media/08/redaxresonerar_3470803.jpg
3554
+ `,
3555
+ preferences: {
3556
+ locale: "de-DE",
3557
+ currency: "EUR",
3558
+ firstDayOfWeek: "monday"
3559
+ }
3560
+ },
3561
+ anakin: {
3562
+ name: "Anakin Skywalker",
3563
+ country: "US",
3564
+ image: `
3565
+ https://thenerdstash.com/wp-content/uploads/2021/10/Hayden-Christensen-Anakin-Skywalker.jpg
3566
+ `,
3567
+ preferences: {
3568
+ locale: "en-US",
3569
+ currency: "USD",
3570
+ firstDayOfWeek: "sunday"
3571
+ }
3572
+ },
3573
+ han: {
3574
+ name: "Han Solo",
3575
+ country: "Sweden",
3576
+ image: `
3577
+ https://fictionhorizon.com/wp-content/uploads/2021/09/Han-Solo.jpg
3578
+ `,
3579
+ preferences: {
3580
+ locale: "sv-SE",
3581
+ currency: "SEK",
3582
+ firstDayOfWeek: "sunday"
3583
+ }
3584
+ },
3585
+ yoda: {
3586
+ name: "Yoda",
3587
+ country: "England",
3588
+ image: `
3589
+ https://markerasomolast.files.wordpress.com/2013/08/yoda.jpg
3590
+ `,
3591
+ preferences: {
3592
+ locale: "en-GB",
3593
+ currency: "GBP",
3594
+ firstDayOfWeek: "monday"
3595
+ }
3596
+ }
3597
+ };
3598
+ const UserContext = createContext(null);
3599
+ const UserProvider = ({ children }) => {
3600
+ const [user, setUser] = useState(users["obi-wan"]);
3601
+ const contextValue = useMemo(() => ({
3602
+ user,
3603
+ setUser
3604
+ }), [user]);
3605
+ return /* @__PURE__ */ React.createElement(UserContext.Provider, { value: contextValue }, children);
3606
+ };
3607
+ const useUser = () => {
3608
+ const context = useContext(UserContext);
3609
+ if (!context) {
3610
+ throw new Error("Cannot find <UserProvider> anywhere in your React tree");
3611
+ }
3612
+ return context;
3613
+ };
3614
+
3615
+ const I18nProvider = ({ children }) => {
3616
+ const { user } = useUser();
3617
+ const i18nManager = useMemo(() => {
3618
+ const { preferences: { locale, currency } } = user;
3619
+ return new I18nManager({
3620
+ locale,
3621
+ currency
3622
+ });
3623
+ }, [user]);
3624
+ return /* @__PURE__ */ React.createElement(I18nContext.Provider, { value: i18nManager }, children);
3625
+ };
3626
+
3627
+ const CalendarProvider = ({ children }) => {
3628
+ const { user: { preferences: { firstDayOfWeek = "monday" } } } = useUser();
3629
+ const calendarLocale = firstDayOfWeek === "monday" ? "en-GB" : "en-US";
3630
+ return /* @__PURE__ */ React.createElement(I18nProvider$1, { locale: calendarLocale }, children);
3631
+ };
3632
+
3633
3633
  const Sandbox = ({ routes }) => {
3634
3634
  const [tott, setTott] = useState(false);
3635
3635
  return /* @__PURE__ */ React.createElement(MediatoolThemeProvider, { theme: tott ? tottTheme : void 0 }, /* @__PURE__ */ React.createElement(UserProvider, null, /* @__PURE__ */ React.createElement(CalendarProvider, null, /* @__PURE__ */ React.createElement(I18nProvider, null, /* @__PURE__ */ React.createElement(BrowserRouter, null, /* @__PURE__ */ React.createElement(
@@ -3665,5 +3665,5 @@ const Sandbox = ({ routes }) => {
3665
3665
  ))))));
3666
3666
  };
3667
3667
 
3668
- export { Sandbox };
3668
+ export { LazyPage, MainMenu, Routing, Sandbox, SearchComponentsBar, SubMenu };
3669
3669
  //# sourceMappingURL=sandbox.mjs.map