Skip to content

Commit

Permalink
Merge pull request #63 from trinhthinh388/master
Browse files Browse the repository at this point in the history
Publish packages
  • Loading branch information
trinhthinh388 authored Jan 31, 2024
2 parents cb1092c + f5ad0d0 commit 83a3e8b
Show file tree
Hide file tree
Showing 15 changed files with 488 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ React Awesome Components is a collection of modern, reusable and well-tested Rea

<p align="center">
<img alt="version" src="https://img.shields.io/npm/v/%40react-awesome%2Fcomponents" />
<img alt="coverage" src="https://img.shields.io/codecov/c/github/trinhthinh388/react-awesome-components/master" />
<img alt="coverage" src="https://codecov.io/gh/trinhthinh388/react-awesome-components/graph/badge.svg?token=VQ8VJ7OECQ)" />
<img alt="license" src="https://img.shields.io/github/license/trinhthinh388/react-awesome-components" />
<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/trinhthinh388/react-awesome-components/release.yml" />
</p>

## Getting Started

Visit <a aria-label="react awesome introduction" href="https://react-awesome-components.vercel.app/introduction">https://react-awesome-components.vercel.app/introduction</a> to get started with React Awesome Components.
Visit <a aria-label="react awesome introduction" href="https://react-awesome-components.vercel.app">https://react-awesome-components.vercel.app</a> to get started with React Awesome Components.

## Documentation

Expand Down
3 changes: 2 additions & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"clean": "rimraf .turbo && rimraf node_modules && rimraf .next"
},
"dependencies": {
"@react-awesome/components": "1.0.6",
"@react-awesome/components": "1.0.7",
"classnames": "^2.5.1",
"lucide-react": "^0.315.0",
"next": "^14.0.4",
"nextra": "^2.13.2",
Expand Down
9 changes: 8 additions & 1 deletion apps/docs/src/pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@
"playground": {
"type": "page",
"title": "Playground",
"href": "https://codesandbox.io/p/devbox/modern-bush-2mzr3w?file=%2Fsrc%2FApp.tsx%3A15%2C1",
"href": "https://codesandbox.io/p/devbox/determined-moon-y7lw4f",
"newWindow": true
},
"about": {
"type": "page",
"title": "About",
"theme": {
"typesetting": "article"
}
},
"404": {
"type": "page",
"theme": {
Expand Down
27 changes: 27 additions & 0 deletions apps/docs/src/pages/about.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: About
---

# About React Awesome Components

Hi guys! My name is [Thinh](https://github.com/trinhthinh388), I've been working as a Fronend Developer for more than {new Date().getFullYear() - 2020} years. During my career, there are so many
components or UI logic that could be reused in the other projects. Thus, I've seen so many libraries having different names but just do exactly same thing,
it makes me tired of choosing the library to best fit my needs. That's why **React Awesome Components** was born.

With **React Awesome Components** you don't have to spend time on finding the next package to use in your project. Just install `@react-awesome/components`.

One package to solve every problem.

# Credits

**React Awesome Components** is powered by these incredible open source projects:

- https://reactjs.org
- https://nextra.site
- https://tailwindcss.com
- https://www.npmjs.com/package/libphonenumber-js
- https://www.npmjs.com/package/@uidotdev/usehooks

## License

The **React Awesome Components** project are licensed under the MIT license.
3 changes: 3 additions & 0 deletions apps/docs/src/pages/docs/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"use-preserve-input-caret-position": {
"title": "usePreserveInputCaretPosition"
},
"use-click-outside": {
"title": "useClickOutside"
},
"-- More": {
"type": "separator",
"title": "More"
Expand Down
8 changes: 0 additions & 8 deletions apps/docs/src/pages/docs/phone-input/use-phone-input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,6 @@ The callback's `event` could be `undefined` when the event is triggered when use
- Type: `(ev: React.ChangeEvent<HTMLInputElement> | undefined, metadata: PhoneInputChangeMetadata) => void`
- Default: `() => void 0`

#### `guessOn` (optional)

Specify event to trigger the guess country function.
When `guessOn` is `true`, the behaviour is equivalent with `change`.

- Type: `'blur' | 'change' | boolean`
- Default: `change`

#### `smartCaret` (optional)

Use smart caret.
Expand Down
90 changes: 90 additions & 0 deletions apps/docs/src/pages/docs/use-click-outside.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: useClickOutside
---

# useClickOutside

**useClickOutside** triggers callback when user clicks on the outside area of an element.

## Install

To start using **useClickOutside**, you can install the `@react-awesome/use-click-outside` library or you can import it directly from `@react-awesome/components` if you have installed it before. In your project directory, run
the following command to install the dependencies:

```sh npm2yarn
npm i @react-awesome/use-click-outside
```

## Usage

import { useState } from 'react'
import { Container } from '../../components/Container'
import { useClickOutside } from '@react-awesome/components'

export const Example = () => {
const [ref, setRef] = useState(null)
const [state, setState] = useState(false)

useClickOutside(ref, () => setState(false))

return (

<div className="mx-auto flex items-center justify-center">
<div ref={setRef}>
<button
onClick={() => setState(true)}
className="relative inline-flex items-center justify-center p-0.5 mb-2 me-2 overflow-hidden text-sm font-medium text-gray-900 rounded-lg group bg-gradient-to-br from-purple-600 to-blue-500 group-hover:from-purple-600 group-hover:to-blue-500 hover:text-white dark:text-white focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800"
>
<span className="relative px-5 py-2.5 transition-all ease-in duration-75 bg-white dark:bg-gray-900 rounded-md group-hover:bg-opacity-0">
Open modal
</span>
</button>
<dialog
open={state}
className="px-6 py-5 bg-purple-400 border border-purple-600 rounded backdrop:bg-gray-50"
>
<p>Hey! click outside to close me.</p>
</dialog>
</div>
</div>
) }

<Container>
<Example />
</Container>

```jsx
import { useClickOutside } from '@react-awesome/use-click-outside'

const Example = () => {
const ref = useRef(null)
const [state, setState] = useState(false)

useClickOutside(ref.current, () => {
setState(false)
})

return (
<>
<div ref={ref}>
<button onClick={() => setState(true)}>Open modal</button>
<dialog open={state}>
<p>Hey! click outside to close me.</p>
</dialog>
</div>
</>
)
}
```

## Parameters

The `useClickOutside` takes the following parameters:

#### `inputEl`

- Type: `HTMLInputElement`

#### `callback`

- Type: `(event: MouseEvent | undefined) => any`
7 changes: 7 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @react-awesome/components

## 1.0.7

### Patch Changes

- Updated dependencies
- @react-awesome/phone-input@1.0.6

## 1.0.6

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-awesome/components",
"version": "1.0.6",
"version": "1.0.7",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -39,7 +39,7 @@
"access": "public"
},
"dependencies": {
"@react-awesome/phone-input": "1.0.5",
"@react-awesome/phone-input": "1.0.6",
"@react-awesome/use-click-outside": "0.0.3",
"@react-awesome/use-preserve-input-caret-position": "0.0.3",
"@react-awesome/use-selection-range": "0.0.3",
Expand Down
8 changes: 8 additions & 0 deletions packages/phone-input/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @react-awesome/phone-input

## 1.0.6

### Patch Changes

- Bug fixes:

- `usePhoneInput` doesn't detect country when received `value` on mount.

## 1.0.5

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/phone-input/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-awesome/phone-input",
"version": "1.0.5",
"version": "1.0.6",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
114 changes: 114 additions & 0 deletions packages/phone-input/src/PhoneInput/PhoneInput.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { PhoneInput } from './PhoneInput'
import { render } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { act } from 'react-dom/test-utils'
import '@testing-library/jest-dom'

const user = userEvent.setup({
delay: 300,
})

const Comp = () => {
return (
<div id="container">
<PhoneInput />
</div>
)
}

describe('PhoneInput', () => {
it('should render phone input', async () => {
const { container } = render(<Comp />)

const input = container.querySelector('input')

if (!input) {
throw new Error('input is not a valid element.')
}

await act(async () => {
input.focus()
await user.keyboard('{a},{b},{c},{1},{2},{3}')
})

expect(input.getAttribute('value')).toBe('+1 23')
})

it('should show country select', async () => {
const { container } = render(<Comp />)

const input = container.querySelector('input')
const countrySelect = container.querySelector('button')

if (!input || !countrySelect) {
throw new Error('input is not a valid element.')
}

await act(async () => {
await user.click(countrySelect)
})

expect(
container.querySelector('ul[class*=selectList]')?.parentElement,
).toBeVisible()
})

it('should close country select when click outside', async () => {
const { container } = render(<Comp />)

const input = container.querySelector('input')
const countrySelect = container.querySelector('div[class*=countrySelect]')

if (!input || !countrySelect) {
throw new Error('input is not a valid element.')
}

await act(async () => {
await user.click(countrySelect)
})

expect(
container.querySelector('ul[class*=selectList]')?.parentElement,
).toBeVisible()

await act(async () => {
await user.click(input)
})

expect(
container
.querySelector('ul[class*=selectList]')
?.parentElement?.classList.value.includes('hidden'),
).toBe(true)
})

it('should close the country select when click on country option', async () => {
const { container } = render(<Comp />)

const input = container.querySelector('input')
const countrySelect = container.querySelector('div[class*=countrySelect]')
const opt = container.querySelector('li')

if (!input || !countrySelect || !opt) {
throw new Error('input is not a valid element.')
}

await act(async () => {
await user.click(countrySelect)
})

expect(
container.querySelector('ul[class*=selectList]')?.parentElement,
).toBeVisible()

await act(async () => {
await user.click(opt)
})

expect(
container
.querySelector('ul[class*=selectList]')
?.parentElement?.classList.value.includes('hidden'),
).toBe(true)
})
})
Loading

0 comments on commit 83a3e8b

Please sign in to comment.