diff --git a/.changeset/beige-penguins-lay.md b/.changeset/beige-penguins-lay.md new file mode 100644 index 00000000..159fc90b --- /dev/null +++ b/.changeset/beige-penguins-lay.md @@ -0,0 +1,6 @@ +--- +"@wethegit/components-cli": patch +"@wethegit/components": patch +--- + +Adds `` component diff --git a/.changeset/config.json b/.changeset/config.json index d4de0c69..e9f6fb3b 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,6 +1,11 @@ { "$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json", - "changelog": "@changesets/cli/changelog", + "changelog": [ + "@changesets/changelog-github", + { + "repo": "wethegit/component-library" + } + ], "commit": false, "fixed": [], "linked": [], diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 50311707..95cb1558 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,10 +1,6 @@ -name: Release +name: Lint on: - push: - branches: - - main - pull_request: types: [opened, edited, reopened, synchronize] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 59fea2c1..f00ed44b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,6 +9,10 @@ concurrency: ${{ github.workflow }}-${{ github.ref }} jobs: release: + permissions: + contents: write # to create release (changesets/action) + issues: write # to post issue comments (changesets/action) + pull-requests: write # to create pull request (changesets/action) name: Release runs-on: ubuntu-latest steps: @@ -34,14 +38,11 @@ jobs: - name: Lint run: yarn lint - - name: Stylelint - run: yarn stylelint - - name: Create Release Pull Request or Publish to npm id: changesets uses: changesets/action@v1 with: - # This expects you to have a script called release which does a build for your packages and calls changeset publish + version: yarn version publish: yarn release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 6975becd..8534d0d2 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Minally styled, accessible, React component primitives that can be copy and past ## Useful Commands - `yarn build` - Build all packages, including the Storybook site -- `yarn dev` - Run all packages locally and preview with Storybook +- `yarn start` - Run all packages locally and preview with Storybook - `yarn lint` - Lint all packages - `yarn changeset` - Generate a changeset - `yarn clean` - Clean up all `node_modules` and `dist` folders (runs each package's clean script) diff --git a/package.json b/package.json index 0d1b9720..b8303661 100755 --- a/package.json +++ b/package.json @@ -1,19 +1,20 @@ { "private": true, "scripts": { - "build": "turbo run build", - "changeset": "changeset", "clean": "turbo run clean && rm -rf .turbo node_modules .turbo-cookie", - "dev": "turbo run dev --no-cache --continue", + "build": "turbo run build", + "start": "turbo run start --no-cache --continue", "format": "prettier --write \"**/*.{ts,tsx,md,mdx}\"", "lint": "turbo run lint stylelint", - "release": "turbo run build && changeset publish", "typecheck": "turbo run typecheck", - "version-packages": "changeset version", + "changeset": "changeset", + "release": "turbo run build && changeset publish", + "version": "changeset version", "prepare": "husky install" }, "devDependencies": { "@changesets/cli": "^2.25.2", + "@changesets/changelog-github": "^0.5.0", "eslint": "^8.48.0", "eslint-config-custom": "*", "husky": "^8.0.3", @@ -28,5 +29,6 @@ "apps/*", "packages/*" ], - "license": "MIT" + "license": "MIT", + "dependencies": {} } diff --git a/packages/wethegit-components-cli/README.md b/packages/wethegit-components-cli/README.md index 7df02ec8..d0480907 100644 --- a/packages/wethegit-components-cli/README.md +++ b/packages/wethegit-components-cli/README.md @@ -11,7 +11,7 @@ To learn how to contribute, continue reading. Make sure you using the required Node version from [nvmrc](./.nvmrc). 1. Run `yarn install` from the **root of the monorepo**, not from this package's directory. -2. `cd` into this package's directory and run `yarn dev` +2. `cd` into this package's directory and run `yarn start` 3. In another terminal run `npm link` from this package's directory. **Note:** it MUST be `npm link` and not `yarn link` Now that we have a local version of the package available we need a node project to test on. If you have one already, skip to step 3. diff --git a/packages/wethegit-components-cli/package.json b/packages/wethegit-components-cli/package.json index c4646c4c..4ad1a034 100644 --- a/packages/wethegit-components-cli/package.json +++ b/packages/wethegit-components-cli/package.json @@ -14,8 +14,8 @@ }, "scripts": { "build": "tsup", - "clean": "rm -rf node_modules dist", - "dev": "tsup --watch", + "clean": "rm -rf ./node_modules ./dist ./.turbo", + "start": "tsup --watch", "lint": "eslint src/", "typecheck": "tsc --noEmit" }, diff --git a/packages/wethegit-components-cli/src/registry-index.ts b/packages/wethegit-components-cli/src/registry-index.ts index c3c6d0de..ac2a10d9 100644 --- a/packages/wethegit-components-cli/src/registry-index.ts +++ b/packages/wethegit-components-cli/src/registry-index.ts @@ -1,4 +1,4 @@ -export type RegistryCategory = "component" | "utility" | "style" | "type" +export type RegistryCategory = "component" | "utility" | "style" | "type" | "hook" export interface Registry { /** Should be the same name as the item's directory */ @@ -92,6 +92,19 @@ const NAVIGATION: Registry = { localDependencies: [FLEX, CLASSNAMES, VISUALLY_HIDDEN, FIXED_FORWARD_REF], } +const ICON: Registry = { + name: "icon", + category: "component", + localDependencies: [CLASSNAMES], +} + +const MODAL: Registry = { + name: "modal", + category: "component", + localDependencies: [CLASSNAMES], + dependencies: ["@wethegit/react-modal", "@wethegit/react-hooks"], +} + /* INDEX */ export const REGISTRY_INDEX: RegistryIndex = { [FLEX.name]: FLEX, @@ -101,5 +114,7 @@ export const REGISTRY_INDEX: RegistryIndex = { [TEXT.name]: TEXT, [VISUALLY_HIDDEN.name]: VISUALLY_HIDDEN, [NAVIGATION.name]: NAVIGATION, + [ICON.name]: ICON, + [MODAL.name]: MODAL, } /* END REGISTRY INDEX */ diff --git a/packages/wethegit-components-cli/src/utils/consts.ts b/packages/wethegit-components-cli/src/utils/consts.ts index a026a8d6..73dcc82e 100644 --- a/packages/wethegit-components-cli/src/utils/consts.ts +++ b/packages/wethegit-components-cli/src/utils/consts.ts @@ -9,6 +9,8 @@ export const COMPONENTS_PACKAGE_STYLES_DIR = "src/styles" export const COMPONENTS_PACKAGE_UTILITIES_DIR = "src/utilities" +export const COMPONENTS_PACKAGE_HOOKS_DIR = "src/hooks" + export const COMPONENTS_PACKAGE_TYPES_DIR = "src/types" export const DEFAULT_CONFIG_FILE_NAME = "components.config.json" @@ -18,6 +20,7 @@ export const DEFAULT_CONFIG: Config = { component: "src/components", style: "src/styles", utility: "src/utilities", + hook: "src/hooks", type: "types", }, } @@ -26,5 +29,6 @@ export const REGISTRY_TYPE_TO_ROOT_DIR_MAP: Record = { component: COMPONENTS_PACKAGE_COMPONENTS_DIR, utility: COMPONENTS_PACKAGE_UTILITIES_DIR, style: COMPONENTS_PACKAGE_STYLES_DIR, + hook: COMPONENTS_PACKAGE_HOOKS_DIR, type: COMPONENTS_PACKAGE_TYPES_DIR, } diff --git a/packages/wethegit-components-cli/src/utils/prompt-for-config.ts b/packages/wethegit-components-cli/src/utils/prompt-for-config.ts index 727d3f0e..6ce026a2 100644 --- a/packages/wethegit-components-cli/src/utils/prompt-for-config.ts +++ b/packages/wethegit-components-cli/src/utils/prompt-for-config.ts @@ -52,6 +52,12 @@ export async function promptForConfig(cwd: string, skip: boolean): Promise { @@ -60,7 +66,13 @@ export async function promptForConfig(cwd: string, skip: boolean): Promise ( +
+ + + +
+ ), + ], +} satisfies Meta + +export default meta + +type Story = StoryObj + +export const Default: Story = { + render: (args) => { + return ( + +

+ Close button doesn't work becayse inside the story we use the{" "} + isOpen control. +

+
+ ) + }, +} + +export const WithButtonTrigger: Story = { + render: () => { + const triggerRef = useRef(null) + const { isOpen, toggle } = useModal({ + triggerRef, + }) + + return ( +
+ + +

+ Close button doesn't work becayse inside the story we use the{" "} + isOpen control. +

+
+
+ ) + }, +} diff --git a/packages/wethegit-components/src/components/modal/modal.tsx b/packages/wethegit-components/src/components/modal/modal.tsx new file mode 100644 index 00000000..9425c57f --- /dev/null +++ b/packages/wethegit-components/src/components/modal/modal.tsx @@ -0,0 +1,58 @@ +"use client" + +import { Modal as WTCModal, ModalContent, ModalBackdrop } from "@wethegit/react-modal" +import type { ModalProps as WTCModalProps } from "@wethegit/react-modal" +import { useAnimatePresence, useUserPrefs } from "@wethegit/react-hooks" + +import { classnames } from "@local/utilities" + +import styles from "./modal.module.scss" + +export interface ModalProps extends WTCModalProps { + /** + * Whether the modal is open or not. + */ + isOpen: boolean + /** + * A function that toggles the modal. + */ + toggle: () => void + /** + * The modal content. + */ + children?: React.ReactNode +} + +/** + * Wrapper around the `@wethegit/react-modal` component that adds a trigger and takes care of reducing motion. + * For more information, see the [modal documentation](https://github.com/wethegit/react-modal). + */ +export function Modal({ children, isOpen, toggle, ...props }: ModalProps) { + const { prefersReducedMotion } = useUserPrefs() + const { render, animate, currentDuration } = useAnimatePresence({ + isVisible: isOpen, + duration: prefersReducedMotion ? 0 : 500, + }) + + const stylesVars = { + "--duration": `${currentDuration}ms`, + } as React.CSSProperties + + if (!render) return null + + return ( + + + + + {children} + + + ) +} diff --git a/packages/wethegit-components/src/components/modal/readme.stories.mdx b/packages/wethegit-components/src/components/modal/readme.stories.mdx new file mode 100644 index 00000000..bd737f24 --- /dev/null +++ b/packages/wethegit-components/src/components/modal/readme.stories.mdx @@ -0,0 +1,57 @@ +import { Meta } from "@storybook/blocks" + + + +# modal + +The `` component is a wrapper around [@wethegit/react-modal](https://github.com/wethegit/react-modal) with some default styles including animation. + +### Install + +```bash +npx @wethegit/components-cli add modal +``` + +### Usage + +First, import the global modal styles from `@wethegit/react-modal` into your global stylesheet or root layout: + +```scss +@import "@wethegit/react-modal/style.css"; +``` + +The `` component takes a `trigger` prop that is a function which receives a `toggle` function as its only argument and should return the element that will trigger the modal. + +It also handles reduced motion by default and because of that you are required to make sure that the modal component renders inside the [UserPreferencesProvider](https://wethegit.github.io/react-hooks/user-preferences-provider). + +```tsx +import { useRef } from "react" +import { useModal } from "@wethegit/react-modal" +import { UserPreferencesProvider } from "@wethegit/react-hooks" + +import { Modal } from "@local/components" + +function Page() { + const triggerRef = useRef(null) + const props = useModal({ + triggerRef, + }) + + return ( + <> + + + +

Modal Content

+

+ Pariatur occaecat quis aliquip excepteur adipisicing minim ipsum qui proident + qui voluptate ut sunt. +

+
+
+ + ) +} +``` diff --git a/turbo.json b/turbo.json index 986b445f..e66d187f 100644 --- a/turbo.json +++ b/turbo.json @@ -7,7 +7,7 @@ }, "lint": {}, "stylelint": {}, - "dev": { + "start": { "cache": false, "persistent": true }, diff --git a/yarn.lock b/yarn.lock index 6d8f897a..2a4569d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1129,7 +1129,25 @@ dependencies: "@changesets/types" "^5.2.1" -"@changesets/cli@^2.25.2": +"@changesets/changelog-github@^0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@changesets/changelog-github/-/changelog-github-0.5.0.tgz#ae96e5029209f7386527b3821d9c988b1ab16662" + integrity sha512-zoeq2LJJVcPJcIotHRJEEA2qCqX0AQIeFE+L21L8sRLPVqDhSXY8ZWAt2sohtBpFZkBwu+LUwMSKRr2lMy3LJA== + dependencies: + "@changesets/get-github-info" "^0.6.0" + "@changesets/types" "^6.0.0" + dotenv "^8.1.0" + +"@changesets/changelog-github@~0.4.8": + version "0.4.8" + resolved "https://registry.yarnpkg.com/@changesets/changelog-github/-/changelog-github-0.4.8.tgz#b7f8ae85d0c0ff08028d924c5e59a1cbd3742634" + integrity sha512-jR1DHibkMAb5v/8ym77E4AMNWZKB5NPzw5a5Wtqm1JepAuIF+hrKp2u04NKM14oBZhHglkCfrla9uq8ORnK/dw== + dependencies: + "@changesets/get-github-info" "^0.5.2" + "@changesets/types" "^5.2.1" + dotenv "^8.1.0" + +"@changesets/cli@^2.25.2", "@changesets/cli@~2.26.2": version "2.26.2" resolved "https://registry.yarnpkg.com/@changesets/cli/-/cli-2.26.2.tgz#8914dd6ef3ea425a7d5935f6c35a8b7ccde54e45" integrity sha512-dnWrJTmRR8bCHikJHl9b9HW3gXACCehz4OasrXpMp7sx97ECuBGGNjJhjPhdZNCvMy9mn4BWdplI323IbqsRig== @@ -1199,6 +1217,22 @@ fs-extra "^7.0.1" semver "^7.5.3" +"@changesets/get-github-info@^0.5.2": + version "0.5.2" + resolved "https://registry.yarnpkg.com/@changesets/get-github-info/-/get-github-info-0.5.2.tgz#0cde2cadba57db85c714dc303c077da919a574e5" + integrity sha512-JppheLu7S114aEs157fOZDjFqUDpm7eHdq5E8SSR0gUBTEK0cNSHsrSR5a66xs0z3RWuo46QvA3vawp8BxDHvg== + dependencies: + dataloader "^1.4.0" + node-fetch "^2.5.0" + +"@changesets/get-github-info@^0.6.0": + version "0.6.0" + resolved "https://registry.yarnpkg.com/@changesets/get-github-info/-/get-github-info-0.6.0.tgz#faba66a20a3a5a0cbabea28efd43c9ede7429f11" + integrity sha512-v/TSnFVXI8vzX9/w3DU2Ol+UlTZcu3m0kXTjTT4KlAdwSvwutcByYwyYn9hwerPWfPkT2JfpoX0KgvCEi8Q/SA== + dependencies: + dataloader "^1.4.0" + node-fetch "^2.5.0" + "@changesets/get-release-plan@^3.0.17": version "3.0.17" resolved "https://registry.yarnpkg.com/@changesets/get-release-plan/-/get-release-plan-3.0.17.tgz#8aabced2795ffeae864696b60ee3031f8a94c5f3" @@ -1280,6 +1314,11 @@ resolved "https://registry.yarnpkg.com/@changesets/types/-/types-5.2.1.tgz#a228c48004aa8a93bce4be2d1d31527ef3bf21f6" integrity sha512-myLfHbVOqaq9UtUKqR/nZA/OY7xFjQMdfgfqeZIBK4d0hA6pgxArvdv8M+6NUzzBsjWLOtvApv8YHr4qM+Kpfg== +"@changesets/types@^6.0.0": + version "6.0.0" + resolved "https://registry.yarnpkg.com/@changesets/types/-/types-6.0.0.tgz#e46abda9890610dd1fbe1617730173d2267544bd" + integrity sha512-b1UkfNulgKoWfqyHtzKS5fOZYSJO+77adgL7DLRDr+/7jhChN+QcHnbjiQVOz/U+Ts3PGNySq7diAItzDgugfQ== + "@changesets/write@^0.2.3": version "0.2.3" resolved "https://registry.yarnpkg.com/@changesets/write/-/write-0.2.3.tgz#baf6be8ada2a67b9aba608e251bfea4fdc40bc63" @@ -3485,6 +3524,20 @@ magic-string "^0.27.0" react-refresh "^0.14.0" +"@wethegit/react-hooks@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@wethegit/react-hooks/-/react-hooks-2.0.0.tgz#ac4668cdbe860c5fb730fdcb884932c3a4e5b53a" + integrity sha512-6SiARtkVTCMD9vhHrNbJ6yNYLYGWslUyBiAIyChMhJDff48o+G8VXLH9ab2fKC40c0c03YbTRpJ0xGgqI4k9lQ== + +"@wethegit/react-modal@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@wethegit/react-modal/-/react-modal-2.0.0.tgz#7f9ced1627e12cc12eba5a0b0fe2ab7edc4d6c4a" + integrity sha512-ESkxhqe5rHPC+bw2XD79QbIjFmmJ8AQD4jyg5C30cFV66s4KiF1nBh03axN1DMElvkrY0DK/DD7GmETKLoTXig== + dependencies: + "@changesets/changelog-github" "~0.4.8" + "@changesets/cli" "~2.26.2" + "@wethegit/react-hooks" "^2.0.0" + "@yarnpkg/esbuild-plugin-pnp@^3.0.0-rc.10": version "3.0.0-rc.15" resolved "https://registry.yarnpkg.com/@yarnpkg/esbuild-plugin-pnp/-/esbuild-plugin-pnp-3.0.0-rc.15.tgz#4e40e7d2eb28825c9a35ab9d04c363931d7c0e67" @@ -4577,6 +4630,11 @@ csv@^5.5.3: csv-stringify "^5.6.5" stream-transform "^2.1.3" +dataloader@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/dataloader/-/dataloader-1.4.0.tgz#bca11d867f5d3f1b9ed9f737bd15970c65dff5c8" + integrity sha512-68s5jYdlvasItOJnCuI2Q9s4q98g0pCyL3HrcKJu8KNugUl8ahgmZYg38ysLTgQjjXX3H8CJLkAvWrclWfcalw== + debug@2.6.9, debug@^2.6.9: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -4791,6 +4849,11 @@ dotenv@^16.0.0: resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== +dotenv@^8.1.0: + version "8.6.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.6.0.tgz#061af664d19f7f4d8fc6e4ff9b584ce237adcb8b" + integrity sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g== + duplexify@^3.5.0, duplexify@^3.6.0: version "3.7.1" resolved "https://registry.yarnpkg.com/duplexify/-/duplexify-3.7.1.tgz#2a4df5317f6ccfd91f86d6fd25d8d8a103b88309" @@ -7837,7 +7900,7 @@ node-fetch-native@^1.4.0: resolved "https://registry.yarnpkg.com/node-fetch-native/-/node-fetch-native-1.4.1.tgz#5a336e55b4e1b1e72b9927da09fecd2b374c9be5" integrity sha512-NsXBU0UgBxo2rQLOeWNZqS3fvflWePMECr8CoSWoSTqCqGbVVsvl9vZu1HfQicYN0g5piV9Gh8RTEvo/uP752w== -node-fetch@^2.0.0: +node-fetch@^2.0.0, node-fetch@^2.5.0: version "2.7.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==