Skip to content

Commit

Permalink
refactor(ui): ui package bundling, closes leather-io/issues#351
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Sep 27, 2024
1 parent 0cb5875 commit b765ced
Show file tree
Hide file tree
Showing 25 changed files with 251 additions and 673 deletions.
2 changes: 1 addition & 1 deletion .github/actions/provision/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ runs:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: '9.6.0'
version: '9.11.0'

- name: Set up node
uses: actions/setup-node@v3
Expand Down
17 changes: 13 additions & 4 deletions packages/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@

This package contains Leather Wallet's UI library for our web + React Native applications.

## Architecture

This package colocates Web and React Native code, such that commonalities such as shared logic and types are shared. **The naming convention must be followed.**

- `*.web.ts` — bundled only for Web
- `*.native.ts` — bundled only for React Native
- `*.shared.ts` — bundled for all platforms

## Web Setup

Our web apps use [panda css](https://panda-css.com/). To setup in your application you need to:

- install panda-css
- setup panda css and configure it to acknowledge the library code
- configure webpack to load the files correctly
- Install `@pandacss/dev`
- Setup panda css and configure it to acknowledge the library code
- Configure Webpack to load the files correctly
- Import the library styles from `@leather.io/ui/styles`

### Panda configuration

Specify the library as part of the `panda.config` `include`:

```js
include: [
'./node_modules/@leather.io/ui/dist-web/src/**/*.{js,jsx,ts,tsx}',
'./node_modules/@leather.io/ui/dist-web/**/*.{js,jsx,ts,tsx}',
'./src/**/*.{js,jsx,ts,tsx}',
],
```
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build-storybook:web": "storybook build -c ./src/.storybook-web",
"build:native": "tsup --config tsup.config.native.ts",
"build:watch": "concurrently \"pnpm panda:watch\" \"pnpm build:native --watch --preserveWatchOutput\" \"pnpm build:web --watch\" ",
"build:web": "tsup --config tsup.config.web.ts",
"build:web": "panda && tsup --config tsup.config.web.ts",
"format": "prettier . --write \"src/**/*.{ts,tsx}\" --ignore-path ../../.prettierignore",
"format:check": "prettier . --check \"src/**/*.{ts,tsx}\" --ignore-path ../../.prettierignore",
"lint": "eslint . --ignore-path ../../.eslintignore",
Expand All @@ -20,7 +20,8 @@
"typecheck": "tsc --noEmit --project ./tsconfig.json"
},
"exports": {
".": "./dist-web/web.js",
".": "./dist-web/exports.web.js",
"./styles": "./dist-web/styles.css",
"./native": "./dist-native/native.js"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/panda.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({

exclude: [],

prefix: 'ui',
prefix: 'leather',

presets: ['@leather.io/panda-preset'],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { HTMLStyledProps } from 'leather-styles/types';
import { isEven } from '@leather.io/utils';

import { AddressDisplayerLayout } from './address-displayer.layout.web';
import { groupByFour } from './address-displayer.utils';
import { groupByFour } from './address-displayer.utils.shared';

interface AddressDisplayerProps extends HTMLStyledProps<'span'> {
address: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useRef, useState } from 'react';

import { motion } from 'framer-motion';

import { HasChildren } from '../../utils/has-children';
import { HasChildren } from '../../utils/has-children.shared';
import { useElementHeightListener } from '../../utils/use-element-height-listener.web';

// https://github.com/framer/motion/discussions/1884#discussioncomment-5861808
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { motion, stagger, useAnimate } from 'framer-motion';
import { css } from 'leather-styles/css';

import { HasChildren } from '../../../utils/has-children';
import { useOnMount } from '../../../utils/use-on-mount';
import { HasChildren } from '../../../utils/has-children.shared';
import { useOnMount } from '../../../utils/use-on-mount.shared';

const animationSelector = '& > *:not(.skip-animation)';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext, useContext } from 'react';

import { useOnMount } from '../../utils/use-on-mount';
import { ChildRegister, useRegisterChildren } from '../../utils/use-register-children';
import { useOnMount } from '../../utils/use-on-mount.shared';
import { ChildRegister, useRegisterChildren } from '../../utils/use-register-children.shared';

type ApproverChildren = 'header' | 'actions' | 'advanced' | 'section' | 'subheader';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { css } from 'leather-styles/css';
import { Flex, styled } from 'leather-styles/jsx';

import type { HasChildren } from '../../../utils/has-children';
import type { HasChildren } from '../../../utils/has-children.shared';
import {
ApproverActionAnimation,
ApproverActionsAnimationContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AnimateChangeInHeight } from '../../../components/animate-height/animat
import { Button } from '../../../components/button/button.web';
import { Flag } from '../../../components/flag/flag.web';
import { ChevronDownIcon } from '../../../icons/chevron-down-icon.web';
import { HasChildren } from '../../../utils/has-children';
import { HasChildren } from '../../../utils/has-children.shared';
import { getScrollParent } from '../../../utils/utils.web';
import { useApproverContext, useRegisterApproverChild } from '../approver-context.shared';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { styled } from 'leather-styles/jsx';

import { HasChildren } from '../../../utils/has-children';
import { HasChildren } from '../../../utils/has-children.shared';
import { useRegisterApproverChild } from '../approver-context.shared';

export function ApproverSection(props: HasChildren) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TooltipProvider } from '@radix-ui/react-tooltip';
import { Box, Circle, styled } from 'leather-styles/jsx';
import { InfoCircleIcon } from 'src/icons/index.web';

import { InfoCircleIcon } from '../../../icons/index.web';
import { Button } from '../../button/button.web';
import { Callout } from '../../callout/callout.web';
import { Flag } from '../../flag/flag.web';
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/input/input.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { SystemStyleObject } from 'leather-styles/types';
import { propIfDefined } from '@leather.io/utils';

import { createStyleContext } from '../../utils/style-context.web';
import { useOnMount } from '../../utils/use-on-mount';
import { useOnMount } from '../../utils/use-on-mount.shared';

const hackyDelayOneMs = 1;

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/toast/toast.layout.web.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, HStack, styled } from 'leather-styles/jsx';

import { getIconVariant } from './toast.utils';
import { getIconVariant } from './toast.utils.web';
import { type ToastProps } from './toast.web';

export function ToastLayout({ message, variant }: ToastProps) {
Expand Down
32 changes: 32 additions & 0 deletions packages/ui/src/exports.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export { Accordion } from './components/accordion/accordion.web';
export { AddressDisplayer } from './components/address-displayer/address-displayer.web';
export * from './components/avatar';
export { BulletSeparator } from './components/bullet-separator/bullet-separator.web';
export { Button, type ButtonProps } from './components/button/button.web';
export { Callout } from './components/callout/callout.web';
export * from './components/sheet';
export { DropdownMenu } from './components/dropdown-menu/dropdown-menu.web';
export { Flag, type FlagProps } from './components/flag/flag.web';
export { IconButton } from './components/icon-button/icon-button.web';
export { Input } from './components/input/input.web';
export { ItemLayout } from './components/item-layout/item-layout.web';
export { ItemLayoutWithButtons } from './components/item-layout/item-layout-with-buttons.web';
export { Link } from './components/link/link.web';
export { NetworkModeBadge } from './components/network-mode-badge/network-mode-badge.web';
export * from './components/pressable/pressable.web';
export * from './components/select';
export { Tabs } from './components/tabs/tabs.web';
export * from './components/toast';
export * from './components/tooltip';
export { Tag, type TagProps, type TagVariants } from './components/tag/tag.web';
export * from './components/typography/index.web';
export { DynamicColorCircle } from './components/dynamic-color-circle.web';
export { Hr, DashedHr, type HrProps } from './components/hr.web';
export { Logo } from './components/logo.web';
export { Spinner } from './components/spinner.web';
export { shimmerStyles } from './components/skeleton-loader/shimmer.styles.web';
export { SkeletonLoader } from './components/skeleton-loader/skeleton-loader.web';
export { Icon } from './icons/icon/icon.web';
export * from './icons/index.web';
export * from './components/approver/approver.web';
export * from './components/favicon/favicon.web';
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/ui/tsconfig.native.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
],
"exclude": [
"node_modules",
"**/*.web.ts",
"**/*.web.tsx",
"babel.config.cjs",
"metro.config.cjs",
"tsup.config.*.ts",
Expand Down
11 changes: 5 additions & 6 deletions packages/ui/tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
"compilerOptions": {
"jsx": "react-jsx",
"lib": ["ESNext", "DOM"],
"baseUrl": ".",
"rootDir": ".",
"baseUrl": "./src",
"outDir": "./dist-web",
"paths": {
"leather-styles/*": ["leather-styles/*"]
"leather-styles/*": ["../leather-styles/*"]
}
},
"include": [
"**/*.web.{ts,tsx}",
"**/*.web.{ts,tsx}",
"web.ts",
"**/*.web.ts",
"**/*.web.tsx",
"web.exports.ts",
"**/*.shared.tsx",
"global.d.ts",
"leather-styles"
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/tsup.config.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineConfig({
inject: ['./react-shim.js'],
format: ['esm'],
tsconfig: 'tsconfig.native.json',
outDir: 'dist-native/',
outDir: 'dist-native',
experimentalDts: true,
clean: false,
minify: true,
Expand Down
17 changes: 9 additions & 8 deletions packages/ui/tsup.config.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@ import svgrPlugin from 'esbuild-plugin-svgr';
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['web.ts'],
entry: ['./src/**/*.{web,shared}.{ts,tsx}', './src/**/index.ts'],
bundle: false,
esbuildPlugins: [
svgrPlugin({ typescript: true }),
copy({
copyOnStart: true,
watch: true,
assets: [
{
from: ['./src/assets/**/*'],
to: ['./src/assets'],
to: ['./assets'],
},
{
from: ['./src/assets-web/**/*'],
to: ['./src/assets-web'],
to: ['./assets-web'],
},
],
copyOnStart: true,
watch: true,
}),
],
onSuccess: 'tsc --build tsconfig.json',
onSuccess: 'panda cssgen --outfile dist-web/styles.css',
format: ['esm'],
tsconfig: 'tsconfig.web.json',
outDir: 'dist-web/',
clean: false,
outDir: 'dist-web',
clean: true,
minify: true,
minifyIdentifiers: true,
minifySyntax: true,
Expand Down
Loading

0 comments on commit b765ced

Please sign in to comment.