Skip to content

Commit

Permalink
feat(dialog): setup dialog template
Browse files Browse the repository at this point in the history
  • Loading branch information
Powerplex committed Jul 27, 2023
1 parent c91c3d1 commit e2fd6fa
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 0 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/components/dialog/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src
**/*.stories.*
29 changes: 29 additions & 0 deletions packages/components/dialog/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@spark-ui/dialog",
"version": "1.0.0",
"description": "A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.",
"publishConfig": {
"access": "public"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"scripts": {
"build": "vite build"
},
"peerDependencies": {
"react": "^16.8 || ^17.0 || ^18.0",
"react-dom": "^16.8 || ^17.0 || ^18.0",
"tailwindcss": "^3.0.0"
},
"repository": {
"type": "git",
"url": "git@github.com:adevinta/spark.git",
"directory": "packages/components/dialog"
},
"bugs": {
"url": "https://github.com/adevinta/spark/issues"
},
"homepage": "https://sparkui.vercel.app",
"license": "MIT"
}
31 changes: 31 additions & 0 deletions packages/components/dialog/src/Dialog.doc.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Meta, Canvas } from '@storybook/addon-docs'
import { ArgTypes } from '@storybook/blocks';

import { Dialog } from '.'

import * as stories from './Dialog.stories'

<Meta of={stories} />

# Dialog

A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.

## Install

```sh
npm install @spark-ui/dialog
```

## Import

```tsx
import { Dialog } from "@spark-ui/dialog"
```

## Props

<ArgTypes of={Dialog} />

## Variants
<Canvas of={stories.Default} />
12 changes: 12 additions & 0 deletions packages/components/dialog/src/Dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Meta, StoryFn } from '@storybook/react'

import { Dialog } from '.'

const meta: Meta<typeof Dialog> = {
title: 'Components/Dialog',
component: Dialog,
}

export default meta

export const Default: StoryFn = _args => <Dialog>Hello World!</Dialog>
Empty file.
27 changes: 27 additions & 0 deletions packages/components/dialog/src/Dialog.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { describe, expect, it, vi } from 'vitest'

import { Dialog } from './Dialog'

describe('Dialog', () => {
it('should render', () => {
render(<Dialog>Hello World!</Dialog>)

expect(screen.getByText('Hello World!')).toBeInTheDocument()
})

it('should trigger click event', async () => {
const user = userEvent.setup()
const clickEvent = vi.fn()

// Given
render(<div onClick={clickEvent}>Hello World!</div>)

// When
await user.click(screen.getByText('Hello World!'))

// Then
expect(clickEvent).toHaveBeenCalledTimes(1)
})
})
7 changes: 7 additions & 0 deletions packages/components/dialog/src/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ComponentPropsWithoutRef, forwardRef, PropsWithChildren } from 'react'

export type DialogProps = ComponentPropsWithoutRef<'div'>

export const Dialog = forwardRef<HTMLDivElement, PropsWithChildren<DialogProps>>((props, ref) => {
return <div ref={ref} {...props} />
})
1 change: 1 addition & 0 deletions packages/components/dialog/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Dialog } from './Dialog'
4 changes: 4 additions & 0 deletions packages/components/dialog/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../../tsconfig.json",
"include": ["src/**/*", "../../../global.d.ts"]
}
6 changes: 6 additions & 0 deletions packages/components/dialog/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import path from 'path'
import { getComponentConfiguration } from '../../../config/index'

const { name } = require(path.resolve(__dirname, 'package.json'))

export default getComponentConfiguration(process.cwd(), name)

0 comments on commit e2fd6fa

Please sign in to comment.