@luxfi/ui 5.5.3 → 6.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/README.md +109 -0
- package/package.json +81 -73
- package/commerce/ui/conf.ts +0 -13
- package/commerce/ui/context.tsx +0 -123
- package/commerce/ui/store.ts +0 -295
- package/components/access-code-input.tsx +0 -71
- package/components/analytics.tsx +0 -23
- package/components/auth/auth-listener.tsx +0 -29
- package/components/auth/auth-token/clear-auth-token.tsx +0 -12
- package/components/auth/auth-token/set-auth-token.tsx +0 -16
- package/components/auth/common-auth-domains.ts +0 -17
- package/components/auth/login-panel.tsx +0 -111
- package/components/auth/mobile-login-button.tsx +0 -107
- package/components/auth/signup-panel.tsx +0 -113
- package/components/back-button.tsx +0 -49
- package/components/chat-widget.tsx +0 -85
- package/components/commerce/bag-button.tsx +0 -98
- package/components/commerce/buy-button.tsx +0 -34
- package/components/commerce/checkout-button.tsx +0 -129
- package/components/commerce/checkout-panel/cart-accordian.tsx +0 -66
- package/components/commerce/checkout-panel/checkout-panel-props.ts +0 -10
- package/components/commerce/checkout-panel/desktop-bag-carousel.tsx +0 -36
- package/components/commerce/checkout-panel/desktop-cp.tsx +0 -83
- package/components/commerce/checkout-panel/index.tsx +0 -126
- package/components/commerce/checkout-panel/mobile-cp.tsx +0 -67
- package/components/commerce/checkout-panel/policy-links.tsx +0 -29
- package/components/commerce/checkout-panel/steps-indicator.tsx +0 -39
- package/components/commerce/checkout-panel/thank-you.tsx +0 -18
- package/components/commerce/desktop-bag-popup.tsx +0 -78
- package/components/commerce/drawer/index.tsx +0 -88
- package/components/commerce/drawer/micro.tsx +0 -145
- package/components/commerce/drawer/shell.tsx +0 -85
- package/components/contact-dialog/contact-form.tsx +0 -116
- package/components/contact-dialog/disclaimer.tsx +0 -13
- package/components/contact-dialog/index.tsx +0 -64
- package/components/copyright.tsx +0 -21
- package/components/drawer-margin.tsx +0 -28
- package/components/footer.tsx +0 -78
- package/components/header/desktop-nav-menu.tsx +0 -204
- package/components/header/desktop.tsx +0 -65
- package/components/header/index.tsx +0 -50
- package/components/header/mobile-bag-drawer.tsx +0 -51
- package/components/header/mobile-menu-toggle-button.tsx +0 -35
- package/components/header/mobile-nav-menu-ai.tsx +0 -51
- package/components/header/mobile-nav-menu-item.tsx +0 -47
- package/components/header/mobile-nav-menu.tsx +0 -102
- package/components/header/mobile.tsx +0 -170
- package/components/header/theme-toggle.tsx +0 -26
- package/components/icons/avatar.tsx +0 -11
- package/components/icons/bag-icon.tsx +0 -10
- package/components/icons/index.ts +0 -6
- package/components/icons/left-arrow.tsx +0 -11
- package/components/icons/lux-logo.tsx +0 -10
- package/components/icons/right-arrow.tsx +0 -10
- package/components/icons/social-icon.tsx +0 -35
- package/components/icons/social-svg.css +0 -3
- package/components/index.ts +0 -26
- package/components/logo.tsx +0 -92
- package/components/main.tsx +0 -27
- package/components/mini-chart/index.tsx +0 -8
- package/components/mini-chart/mini-chart-props.ts +0 -44
- package/components/mini-chart/mini-chart.tsx +0 -85
- package/components/mini-chart/wrapper.tsx +0 -23
- package/components/not-found/index.tsx +0 -28
- package/components/not-found/not-found-content.mdx +0 -5
- package/components/tooltip.tsx +0 -31
- package/environment.d.ts +0 -6
- package/next/analytics/fpixel.ts +0 -16
- package/next/analytics/google-analytics.ts +0 -14
- package/next/analytics/index.ts +0 -3
- package/next/analytics/pixel-analytics.tsx +0 -55
- package/next/font/get-app-router-font-classes.ts +0 -17
- package/next/font/load-and-return-lux-next-fonts-on-import.ts +0 -68
- package/next/font/local/Druk-Wide-Bold.ttf +0 -0
- package/next/font/local/Druk-Wide-Medium.ttf +0 -0
- package/next/font/local/InterVariable-Italic.ttf +0 -0
- package/next/font/local/InterVariable-Italic.woff2 +0 -0
- package/next/font/local/InterVariable.ttf +0 -0
- package/next/font/local/InterVariable.woff2 +0 -0
- package/next/font/next-font-desc.ts +0 -28
- package/next/font/pages-router-font-vars.tsx +0 -18
- package/next/head-metadata/from-next/metadata-types.ts +0 -158
- package/next/head-metadata/from-next/opengraph-types.ts +0 -267
- package/next/head-metadata/from-next/twitter-types.ts +0 -92
- package/next/head-metadata/index.tsx +0 -208
- package/next/index.ts +0 -2
- package/next/middleware/determine-device-mw.ts +0 -29
- package/root-layout/WHY_THIS_IS_SEPARATE.txt +0 -2
- package/root-layout/index.tsx +0 -112
- package/site-def/footer/community.tsx +0 -61
- package/site-def/footer/company.ts +0 -37
- package/site-def/footer/ecosystem.ts +0 -37
- package/site-def/footer/index.tsx +0 -26
- package/site-def/footer/legal.ts +0 -28
- package/site-def/footer/network.ts +0 -45
- package/site-def/footer/svg/warpcast-logo.svg +0 -12
- package/site-def/index.ts +0 -4
- package/site-def/main-nav.tsx +0 -460
- package/style/cart-animation.css +0 -29
- package/style/checkout-animation.css +0 -23
- package/style/drawer-handle-overrides.css +0 -160
- package/style/fonts/COPY_TO_PUBLIC_FOR_NON_NEXT.txt +0 -0
- package/style/fonts/Druk-Wide-Bold.ttf +0 -0
- package/style/fonts/Druk-Wide-Medium.ttf +0 -0
- package/style/fonts/InterVariable-Italic.ttf +0 -0
- package/style/fonts/InterVariable-Italic.woff2 +0 -0
- package/style/fonts/InterVariable.ttf +0 -0
- package/style/fonts/InterVariable.woff2 +0 -0
- package/style/lux-colors.css +0 -85
- package/style/lux-fonts.css +0 -30
- package/style/lux-global-non-next.css +0 -52
- package/style/lux-global.css +0 -51
- package/tailwind/fontFamily.tailwind.lux.ts +0 -18
- package/tailwind/index.ts +0 -2
- package/tailwind/lux-tw-fonts.ts +0 -40
- package/tailwind/tailwind.config.lux-preset.ts +0 -10
- package/tsconfig.json +0 -15
- package/types/chatbot-config.ts +0 -7
- package/types/chatbot-suggested-question.ts +0 -7
- package/types/contact-info.ts +0 -11
- package/types/index.ts +0 -4
- package/types/site-def.ts +0 -46
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# `ui` Package
|
|
2
|
+
|
|
3
|
+
This package holds a component library and themes that can be used across all apps.
|
|
4
|
+
|
|
5
|
+
## UI Package Philosophy
|
|
6
|
+
|
|
7
|
+
The `ui` package contains all low level components that are shared between apps. It should *not* contain components that are specific to any one app or Uniswap business logic. Each component should be guided by the following principles:
|
|
8
|
+
|
|
9
|
+
- All components should be compatible with all platforms.
|
|
10
|
+
- Wrap as many implementation details as possible, including any direct exports from Tamagui.
|
|
11
|
+
- Export only what’s needed from `ui/src` or another allowlisted path.
|
|
12
|
+
- Only include components that will be used beyond a single feature.
|
|
13
|
+
|
|
14
|
+
Components that are shared between all applications but encode Uniswap business logic should most likely be placed in the `uniswap` package!
|
|
15
|
+
|
|
16
|
+
## Icons and Logos
|
|
17
|
+
|
|
18
|
+
Icons and logos are placed in `ui/src/components/{icons|logos}`. These files are generated from placing the file in `packages/ui/src/assets/icons` or `packages/ui/src/assets/logos/svg` and running the generate command(s):
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Generate all icons
|
|
22
|
+
bun ui build:icons
|
|
23
|
+
# Generate any icons that do not yet have an existing TS file
|
|
24
|
+
bun ui build:icons:missing
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
When adding an SVG, please ensure you replace color references as needed with `currentColor` to ensure the asset respects the color property when used.
|
|
28
|
+
|
|
29
|
+
Custom icons that take props can be added to the same icons import by adding the file in `packages/ui/src/components/icons/index.ts`.
|
|
30
|
+
|
|
31
|
+
## Core Components
|
|
32
|
+
|
|
33
|
+
Many base components are available in the UI library. While some are customized `tamagui` elements or even fully custom elements, many are simple or direct exposure of `tamagui` elements. If you would like to use any `tamagui` elements, please add them through this library to ensure a layer of abstraction between tamagui and our usage when possible.
|
|
34
|
+
|
|
35
|
+
Below are summaries of the most commonly used elements.
|
|
36
|
+
|
|
37
|
+
### Flex
|
|
38
|
+
|
|
39
|
+
The `Flex` component is the core organizational element of the UI library, acting as a base of a flexbox styling approach. Shortcuts are available for `row`, `grow`, `shrink`, `fill`, and `centered`. All other styling props can be added directly as needed.
|
|
40
|
+
|
|
41
|
+
### Text
|
|
42
|
+
|
|
43
|
+
The `Text` element is the core element for displaying text through the app. The `variant` prop takes in the text variant from our design system (e.g `heading1`, `body2`, etc.) that is desired. All other text styling props can be added directly as needed.
|
|
44
|
+
|
|
45
|
+
## Theme and Platform
|
|
46
|
+
|
|
47
|
+
### Theming
|
|
48
|
+
|
|
49
|
+
Theming is applied through two primary methods:
|
|
50
|
+
|
|
51
|
+
1. Any components that take in design systems values (e.g `heading1`, `body2`, etc.) will automatically respect the theme.
|
|
52
|
+
2. In all other cases, `useSporeColors` will return the current theme colors to be used in any component.
|
|
53
|
+
|
|
54
|
+
To force a specific theme usage, the `Theme` wrapper will ensure other theme elements pick up the specific theme.
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
<Theme name="dark">
|
|
58
|
+
...
|
|
59
|
+
</Theme>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Screen Size Differences
|
|
63
|
+
|
|
64
|
+
All breakpoints for both vertical and horizontal sizing have been defined in `packages/ui/src/theme/breakpoints.ts`.
|
|
65
|
+
|
|
66
|
+
To account for screen size references, components take in props to adapt custom style per breakpoint, like so:
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
<Flex
|
|
70
|
+
margin="20"
|
|
71
|
+
$short={{ margin: 10 }}
|
|
72
|
+
>
|
|
73
|
+
...
|
|
74
|
+
</Flex>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
When components cannot take in these props or a value needs to be resued multiple times, the `useMedia` hook allows these same breakpoint values to be defined programmatically.
|
|
78
|
+
|
|
79
|
+
### Colors
|
|
80
|
+
|
|
81
|
+
We've made a hook `useSporeColors()` which gives you access to the current theme, and you can access the values off it as follows:
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import { useSporeColors } from 'ui/src'
|
|
85
|
+
|
|
86
|
+
function MyComponent() {
|
|
87
|
+
const colors = useSporeColors()
|
|
88
|
+
|
|
89
|
+
colors.accent1.val // returns something like #fff
|
|
90
|
+
colors.accent1.get() // returns a "dynamic" color value
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### When to use `.get()` vs `.val`
|
|
95
|
+
|
|
96
|
+
After some discussion we've come to prefer `.val` by default. This will always return the raw string color (in our case hex color) on all platforms, whereas `.get()` returns either an Object (iOS) or a string, which can cause issues when used with things like animations, or external components.
|
|
97
|
+
|
|
98
|
+
Using .val has some performance downside vs .get in that all usages of .val will re-render when themes change, whereas .get will avoid re-renders on iOS and Web by optimizing to platform-specific constructs. On iOS, it optimizes to [DynamicColorIOS](https://reactnative.dev/docs/dynamiccolorios), on web a CSS variable like `var(--accent1)`.
|
|
99
|
+
|
|
100
|
+
So if/when we notice slowness in our light/dark mode change, we'll want to check if our usages of .val are causing expensive re-renders and see if we can convert them to .get.
|
|
101
|
+
|
|
102
|
+
In summary:
|
|
103
|
+
|
|
104
|
+
- Prefer `.val` which always returns the original color string, like `#fff`.
|
|
105
|
+
- Using `.get()` returns a dynamic value depending on the platform and avoids re-rendering when themes change between light and dark. This is nice for fast light/dark mode switching (and in the future if we use sub-themes, it would also avoid re-renders there).
|
|
106
|
+
- On Android it returns the same as .val, `#fff`
|
|
107
|
+
- On iOS, it returns an object like `{ dynamic: { light: '#fff', dark: '#000' } }`
|
|
108
|
+
- On the web, it returns a CSS variable string, `var(--colorName)`
|
|
109
|
+
- You can call `.get('web')` to only optimize for web, or `.get('ios')` to only optimize for ios.
|
package/package.json
CHANGED
|
@@ -1,81 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxfi/ui",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
3
|
+
"version": "6.0.0",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@gorhom/bottom-sheet": "4.6.4",
|
|
6
|
+
"@react-native-masked-view/masked-view": "0.3.2",
|
|
7
|
+
"@shopify/flash-list": "1.7.6",
|
|
8
|
+
"@shopify/react-native-skia": "2.2.20",
|
|
9
|
+
"@storybook/react": "8.5.2",
|
|
10
|
+
"@hanzogui/adapt": "2.0.1",
|
|
11
|
+
"@hanzogui/animations-css": "2.0.1",
|
|
12
|
+
"@hanzogui/animations-react-native": "2.0.1",
|
|
13
|
+
"@hanzogui/font-geist-sans": "2.0.1",
|
|
14
|
+
"@hanzogui/helpers-icon": "2.0.1",
|
|
15
|
+
"@hanzogui/portal": "2.0.1",
|
|
16
|
+
"@hanzogui/react-native-media-driver": "2.0.1",
|
|
17
|
+
"@hanzogui/remove-scroll": "2.0.1",
|
|
18
|
+
"@hanzogui/theme-base": "2.0.1",
|
|
19
|
+
"@tanstack/react-query": "5.90.20",
|
|
20
|
+
"@testing-library/react": "16.3.0",
|
|
21
|
+
"ethers": "5.7.2",
|
|
22
|
+
"expo-blur": "14.1.5",
|
|
23
|
+
"expo-linear-gradient": "14.1.5",
|
|
24
|
+
"i18next": "23.10.0",
|
|
25
|
+
"qrcode": "1.5.1",
|
|
26
|
+
"react": "19.0.3",
|
|
27
|
+
"react-i18next": "14.1.0",
|
|
28
|
+
"react-native": "0.79.5",
|
|
29
|
+
"react-native-fast-image": "8.6.3",
|
|
30
|
+
"react-native-gesture-handler": "2.24.0",
|
|
31
|
+
"react-native-image-colors": "1.5.2",
|
|
32
|
+
"react-native-keyboard-controller": "1.17.5",
|
|
33
|
+
"react-native-reanimated": "3.19.3",
|
|
34
|
+
"react-native-safe-area-context": "5.4.0",
|
|
35
|
+
"react-native-svg": "15.13.0",
|
|
36
|
+
"react-native-webview": "13.13.5",
|
|
37
|
+
"@hanzo/gui": "2.0.1",
|
|
38
|
+
"@luxfi/utilities": "^1.0.0",
|
|
39
|
+
"uuid": "9.0.0",
|
|
40
|
+
"wcag-contrast": "3.0.0"
|
|
9
41
|
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@storybook/test": "8.5.2",
|
|
44
|
+
"@hanzogui/animations-moti": "2.0.1",
|
|
45
|
+
"@hanzogui/core": "2.0.1",
|
|
46
|
+
"@types/chrome": "0.0.304",
|
|
47
|
+
"@types/fs-extra": "11.0.2",
|
|
48
|
+
"@types/node": "22.13.1",
|
|
49
|
+
"@types/qrcode": "1.5.5",
|
|
50
|
+
"@typescript/native-preview": "7.0.0-dev.20260108.1",
|
|
51
|
+
"@luxfi/eslint-config": "^1.0.0",
|
|
52
|
+
"@vitejs/plugin-react": "4.7.0",
|
|
53
|
+
"camelcase": "6.3.0",
|
|
54
|
+
"cheerio": "1.0.0-rc.12",
|
|
55
|
+
"esbuild-register": "3.6.0",
|
|
56
|
+
"eslint": "8.57.1",
|
|
57
|
+
"fs-extra": "11.2.0",
|
|
58
|
+
"jsdom": "20.0.3",
|
|
59
|
+
"typescript": "5.8.3",
|
|
60
|
+
"uppercamelcase": "3.0.0",
|
|
61
|
+
"vitest": "3.2.1",
|
|
62
|
+
"vitest-presets": "*"
|
|
14
63
|
},
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"luxdefi"
|
|
20
|
-
],
|
|
64
|
+
"files": ["types", "dist"],
|
|
65
|
+
"main": "./src/index.ts",
|
|
66
|
+
"module:jsx": "src",
|
|
67
|
+
"private": false,
|
|
21
68
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
69
|
+
"build:icons": "nx build:icons ui",
|
|
70
|
+
"build:icons:missing": "nx build:icons:missing ui",
|
|
71
|
+
"check:deps:usage": "nx check:deps:usage ui",
|
|
72
|
+
"lint": "nx lint ui",
|
|
73
|
+
"lint:fix": "nx lint:fix ui",
|
|
74
|
+
"lint:biome": "nx lint:biome ui",
|
|
75
|
+
"lint:biome:fix": "nx lint:biome:fix ui",
|
|
76
|
+
"lint:eslint": "nx lint:eslint ui",
|
|
77
|
+
"lint:eslint:fix": "nx lint:eslint:fix ui",
|
|
78
|
+
"test": "nx test ui",
|
|
79
|
+
"test:coverage": "nx test:coverage ui",
|
|
80
|
+
"typecheck": "nx typecheck ui",
|
|
81
|
+
"typecheck:tsgo": "nx typecheck:tsgo ui",
|
|
82
|
+
"watch": "nx watch ui"
|
|
36
83
|
},
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"cookies-next": "^4.1.1",
|
|
40
|
-
"date-fns": "^3.6.0",
|
|
41
|
-
"embla-carousel-autoplay": "^8.1.6",
|
|
42
|
-
"firebase": "10.12.0",
|
|
43
|
-
"framer-motion": "^11.2.12",
|
|
44
|
-
"react-device-detect": "^2.2.3",
|
|
45
|
-
"react-social-icons": "^6.4.0",
|
|
46
|
-
"react-tooltip": "^5.26.4",
|
|
47
|
-
"request": "^2.88.2",
|
|
48
|
-
"usehooks-ts": "^3.1.0"
|
|
49
|
-
},
|
|
50
|
-
"peerDependencies": {
|
|
51
|
-
"@hanzo/auth": "catalog:",
|
|
52
|
-
"@hanzo/commerce": "catalog:",
|
|
53
|
-
"@hanzo/ui": "catalog:",
|
|
54
|
-
"@luxfi/menu-icons": "1.0.2",
|
|
55
|
-
"@hookform/resolvers": "^3.3.2",
|
|
56
|
-
"lucide-react": "catalog:",
|
|
57
|
-
"mobx": "^6.12.3",
|
|
58
|
-
"mobx-react-lite": "^4.0.7",
|
|
59
|
-
"next": "catalog:",
|
|
60
|
-
"next-themes": "^0.2.1",
|
|
61
|
-
"react": "catalog:",
|
|
62
|
-
"react-dom": "catalog:",
|
|
63
|
-
"react-hook-form": "catalog:",
|
|
64
|
-
"validator": "^13.11.0",
|
|
65
|
-
"zod": "3.23.8"
|
|
84
|
+
"nx": {
|
|
85
|
+
"includedScripts": []
|
|
66
86
|
},
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
"@mdx-js/loader": "^3.0.0",
|
|
70
|
-
"@mdx-js/react": "^3.0.0",
|
|
71
|
-
"@types/facebook-pixel": "^0.0.30",
|
|
72
|
-
"@types/gtag.js": "^0.0.19",
|
|
73
|
-
"@types/mdx": "^2.0.9",
|
|
74
|
-
"@types/node": "catalog:",
|
|
75
|
-
"@types/react": "catalog:",
|
|
76
|
-
"@types/react-dom": "catalog:",
|
|
77
|
-
"@types/validator": "^13.12.1",
|
|
78
|
-
"tailwindcss": "catalog:",
|
|
79
|
-
"typescript": "catalog:"
|
|
80
|
-
}
|
|
87
|
+
"sideEffects": ["*.css"],
|
|
88
|
+
"types": "./types/index"
|
|
81
89
|
}
|
package/commerce/ui/conf.ts
DELETED
package/commerce/ui/context.tsx
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import React, {
|
|
3
|
-
createContext,
|
|
4
|
-
useContext,
|
|
5
|
-
useRef,
|
|
6
|
-
type PropsWithChildren,
|
|
7
|
-
useEffect,
|
|
8
|
-
useLayoutEffect
|
|
9
|
-
} from 'react'
|
|
10
|
-
import { enableStaticRendering } from 'mobx-react-lite'
|
|
11
|
-
import { usePathname } from 'next/navigation'
|
|
12
|
-
import { useDebounceCallback } from 'usehooks-ts'
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import { preset as twConfig } from '@hanzo/ui/tailwind'
|
|
16
|
-
import { useCommerce } from '@hanzo/commerce'
|
|
17
|
-
|
|
18
|
-
import type { CommerceDrawer, SelectAndBuy } from './store'
|
|
19
|
-
import { CommerceUIStore } from './store'
|
|
20
|
-
import conf from './conf'
|
|
21
|
-
|
|
22
|
-
const LOG = false ////////////////////
|
|
23
|
-
const log = (s: string) => {
|
|
24
|
-
if (LOG) {
|
|
25
|
-
console.log('CMMC UI CONTEXT ' + s)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// https://dev.to/ivandotv/mobx-server-side-rendering-with-next-js-4m18
|
|
30
|
-
enableStaticRendering(typeof window === "undefined")
|
|
31
|
-
|
|
32
|
-
const CommerceUIContext = createContext<CommerceUIStore | undefined>(undefined)
|
|
33
|
-
|
|
34
|
-
const useCommerceDrawer = (): CommerceDrawer => {
|
|
35
|
-
return useContext(CommerceUIContext) as CommerceDrawer
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const useSelectAndBuy = (): SelectAndBuy => {
|
|
39
|
-
return useContext(CommerceUIContext) as SelectAndBuy
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const CommerceUIProvider: React.FC<PropsWithChildren> = ({
|
|
43
|
-
children,
|
|
44
|
-
}) => {
|
|
45
|
-
|
|
46
|
-
const cmmc = useCommerce()
|
|
47
|
-
const pathname = usePathname()
|
|
48
|
-
const storeRef = useRef<CommerceUIStore>(new CommerceUIStore(cmmc, conf))
|
|
49
|
-
const prevPathRef = useRef<string>('initial')
|
|
50
|
-
|
|
51
|
-
const onResize = () => {
|
|
52
|
-
const width = window.innerWidth
|
|
53
|
-
let desktopMin = 0
|
|
54
|
-
if (twConfig.theme?.screens) {
|
|
55
|
-
// expected form: { md: '768px' }
|
|
56
|
-
if ('md' in twConfig.theme?.screens && typeof twConfig.theme?.screens.md === 'string') {
|
|
57
|
-
desktopMin = parseInt(twConfig.theme?.screens.md)
|
|
58
|
-
}
|
|
59
|
-
if (width < desktopMin) {
|
|
60
|
-
if (!storeRef.current.isMobile) {
|
|
61
|
-
storeRef.current.setMobile(true)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (storeRef.current.isMobile) {
|
|
65
|
-
storeRef.current.setMobile(false)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
storeRef.current.setViewportHeight(window.innerHeight)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const onResize_debounced = useDebounceCallback(onResize, 500)
|
|
72
|
-
|
|
73
|
-
useLayoutEffect(() => {
|
|
74
|
-
storeRef.current.initialize()
|
|
75
|
-
onResize()
|
|
76
|
-
window.addEventListener('resize', onResize_debounced);
|
|
77
|
-
|
|
78
|
-
return () => {
|
|
79
|
-
window.removeEventListener('resize', onResize_debounced)
|
|
80
|
-
storeRef.current.dispose()
|
|
81
|
-
}
|
|
82
|
-
}, [])
|
|
83
|
-
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
const checkingOut = (pathname === '/checkout')
|
|
86
|
-
|
|
87
|
-
/////////////////////////////////////
|
|
88
|
-
log("useEffect: pathname: " + pathname)
|
|
89
|
-
log("useEffect: prev pathname: " + prevPathRef.current)
|
|
90
|
-
|
|
91
|
-
if (storeRef.current.checkingOut === undefined || storeRef.current._checkingOut!== checkingOut) {
|
|
92
|
-
log("useEffect: setting checkingOut to: " + checkingOut) /////////////////////////////////////
|
|
93
|
-
storeRef.current.setCheckingOut(checkingOut)
|
|
94
|
-
}
|
|
95
|
-
if ( prevPathRef.current === 'initial') {
|
|
96
|
-
prevPathRef.current = pathname
|
|
97
|
-
storeRef.current.newRoute()
|
|
98
|
-
}
|
|
99
|
-
else if (
|
|
100
|
-
!checkingOut
|
|
101
|
-
&&
|
|
102
|
-
prevPathRef.current !== pathname
|
|
103
|
-
) {
|
|
104
|
-
storeRef.current.newRoute()
|
|
105
|
-
prevPathRef.current = pathname
|
|
106
|
-
log("ROUTE CHANGE: " + pathname + ": " + storeRef.current._routeChangedTime)
|
|
107
|
-
}
|
|
108
|
-
}, [pathname])
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
<CommerceUIContext.Provider value={storeRef.current}>
|
|
113
|
-
{children}
|
|
114
|
-
</CommerceUIContext.Provider>
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export {
|
|
119
|
-
useCommerceDrawer,
|
|
120
|
-
useSelectAndBuy,
|
|
121
|
-
CommerceUIProvider
|
|
122
|
-
}
|
|
123
|
-
|