Skip to content

Commit

Permalink
Merge pull request #63 from wethegit/feature/comp/modal
Browse files Browse the repository at this point in the history
feature(comp): adds `<Modal>` component
  • Loading branch information
marlonmarcello authored Dec 4, 2023
2 parents 5542dc3 + f7a7eb4 commit 6a272a2
Show file tree
Hide file tree
Showing 22 changed files with 377 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .changeset/beige-penguins-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@wethegit/components-cli": patch
"@wethegit/components": patch
---

Adds `<Modal />` component
7 changes: 6 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"changelog": [
"@changesets/changelog-github",
{
"repo": "wethegit/component-library"
}
],
"commit": false,
"fixed": [],
"linked": [],
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Release
name: Lint

on:
push:
branches:
- main

pull_request:
types: [opened, edited, reopened, synchronize]

Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -28,5 +29,6 @@
"apps/*",
"packages/*"
],
"license": "MIT"
"license": "MIT",
"dependencies": {}
}
2 changes: 1 addition & 1 deletion packages/wethegit-components-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/wethegit-components-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
17 changes: 16 additions & 1 deletion packages/wethegit-components-cli/src/registry-index.ts
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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,
Expand All @@ -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 */
4 changes: 4 additions & 0 deletions packages/wethegit-components-cli/src/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -18,6 +20,7 @@ export const DEFAULT_CONFIG: Config = {
component: "src/components",
style: "src/styles",
utility: "src/utilities",
hook: "src/hooks",
type: "types",
},
}
Expand All @@ -26,5 +29,6 @@ export const REGISTRY_TYPE_TO_ROOT_DIR_MAP: Record<RegistryCategory, string> = {
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,
}
15 changes: 14 additions & 1 deletion packages/wethegit-components-cli/src/utils/prompt-for-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export async function promptForConfig(cwd: string, skip: boolean): Promise<Confi
message: `What is your ${highlight("utilities")} directory?`,
initial: DEFAULT_CONFIG.directories.utility,
},
{
type: "text",
name: "hooksRootDir",
message: `What is your ${highlight("hooks")} directory?`,
initial: DEFAULT_CONFIG.directories.hook,
},
],
{
onCancel: () => {
Expand All @@ -60,7 +66,13 @@ export async function promptForConfig(cwd: string, skip: boolean): Promise<Confi
}
)

const { typesRootDir, componentsRootDir, stylesRootDir, utilitiesRootDir } = response
const {
typesRootDir,
componentsRootDir,
stylesRootDir,
utilitiesRootDir,
hooksRootDir,
} = response
const { directories, ...defaultConfig } = DEFAULT_CONFIG

config = {
Expand All @@ -70,6 +82,7 @@ export async function promptForConfig(cwd: string, skip: boolean): Promise<Confi
component: componentsRootDir,
style: stylesRootDir,
utility: utilitiesRootDir,
hook: hooksRootDir,
...(typesRootDir ? { type: typesRootDir } : {}),
},
}
Expand Down
1 change: 1 addition & 0 deletions packages/wethegit-components/.storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { withThemeByClassName } from "@storybook/addon-themes"

import { wtcTheme } from "./static/wtc-theme"

import "@wethegit/react-modal/style.css"
import "./styles/global-story-styles.scss"

const preview: Preview = {
Expand Down
4 changes: 2 additions & 2 deletions packages/wethegit-components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ You will develop and test the components with **Storybook**.
From the **root** of the repository, run:

```sh
yarn install
yarn dev
yarn
yarn start
```

This will start Storybook and watch for changes in the components' source files.
Expand Down
12 changes: 8 additions & 4 deletions packages/wethegit-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
},
"scripts": {
"build": "storybook build --docs",
"clean": "rm -rf .turbo node_modules dist storybook-static",
"dev": "storybook dev -p 6006",
"clean": "rm -rf ./.turbo ./node_modules ./dist ./storybook-static",
"start": "storybook dev -p 6006",
"lint": "eslint src/",
"stylelint": "stylelint **/*.{css,scss}",
"preview-storybook": "serve storybook-static",
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@wethegit/react-hooks": "^2.0.0",
"@wethegit/react-modal": "^2.0.0",
"react": "17 - 18",
"react-dom": "17 - 18",
"typescript": "5.1.6"
},
"devDependencies": {
Expand All @@ -45,6 +47,8 @@
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"@vitejs/plugin-react": "^1.3.2",
"@wethegit/react-hooks": "^2.0.0",
"@wethegit/react-modal": "^2.0.0",
"eslint": "^8.15.0",
"eslint-config-custom": "*",
"eslint-plugin-storybook": "^0.6.15",
Expand Down
1 change: 1 addition & 0 deletions packages/wethegit-components/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./flex"
export * from "./grid-layout"
export * from "./icon"
export * from "./image-group"
export * from "./modal"
export * from "./navigation"
export * from "./tag"
export * from "./text"
Expand Down
2 changes: 2 additions & 0 deletions packages/wethegit-components/src/components/modal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Modal } from "./modal"
export type { ModalProps } from "./modal"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.modal {
opacity: var(--scale, 0);
transition: opacity var(--duration) ease-in-out;
}

.modalOpen {
--ease: cubic-bezier(0.77, 0, 0.1, 1.39);
--scale: 1;
}

.modalBackdrop {
background-color: rgb(0 0 0 / 70%);
}

.modalCloseButton {
background-color: yellow;
border: none;
border-radius: 0.25rem;
color: black;
cursor: pointer;
font-size: 1rem;
padding: 0.5em 1em;
position: absolute;
right: 1em;
top: -0.5em;
}

.modalContent {
background-color: white;
border-radius: 1rem;
box-shadow: 0 0 5px 0 rgb(0 0 0 / 20%);
font-family: sans-serif;
max-width: 70%;
-webkit-overflow-scrolling: touch;
padding: 2rem;
transform: scale(var(--scale, 0));
transition: transform var(--duration) var(--ease, cubic-bezier(0.75, -0.46, 0.4, 1));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import type { Meta, StoryObj } from "@storybook/react"
import { UserPreferencesProvider } from "@wethegit/react-hooks"
import { useModal } from "@wethegit/react-modal"
import { useRef } from "react"

import { Modal } from "./modal"

const meta = {
title: "components/modal",
component: Modal,
args: {
isOpen: true,
},
decorators: [
(Story) => (
<div style={{ height: 500 }}>
<UserPreferencesProvider>
<Story />
</UserPreferencesProvider>
</div>
),
],
} satisfies Meta<typeof Modal>

export default meta

type Story = StoryObj<typeof Modal>

export const Default: Story = {
render: (args) => {
return (
<Modal {...args} appendToBody={false}>
<p style={{ color: "black", margin: 0 }}>
<strong>Close</strong> button doesn't work becayse inside the story we use the{" "}
<code>isOpen</code> control.
</p>
</Modal>
)
},
}

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

return (
<div
style={{
display: "flex",
justifyContent: "center",
height: "100%",
alignItems: "center",
}}
>
<button
ref={triggerRef}
onClick={toggle}
style={{
backgroundColor: "cyan",
padding: "20px",
color: "black",
fontFamily: "sans-serif",
borderRadius: "5px",
}}
>
{isOpen ? "Close" : "Open"} Modal
</button>
<Modal isOpen={isOpen} toggle={toggle}>
<p style={{ color: "black", margin: 0 }}>
<strong>Close</strong> button doesn't work becayse inside the story we use the{" "}
<code>isOpen</code> control.
</p>
</Modal>
</div>
)
},
}
Loading

0 comments on commit 6a272a2

Please sign in to comment.