-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Button * Update changelog
- Loading branch information
Showing
33 changed files
with
1,182 additions
and
554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
"creativecode", | ||
"cssnano", | ||
"daisyui", | ||
"docgen", | ||
"Docgen", | ||
"firefox", | ||
"tailwindcss", | ||
"testid", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/hooks/__snapshots__/use-safe-button-props.hook.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`useSafeButtonProps should return props 1`] = ` | ||
{ | ||
"disabled": false, | ||
"onClick": [Function], | ||
"onSubmit": [Function], | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import useSafeButtonProps from './use-safe-button-props.hook'; | ||
|
||
export { useSafeButtonProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { renderHook } from '@testing-library/react'; | ||
|
||
import useSafeButtonProps from './use-safe-button-props.hook'; | ||
|
||
describe('useSafeButtonProps', () => { | ||
it('disabled false should execute events', () => { | ||
const props = { | ||
onClick: jest.fn(), | ||
onSubmit: jest.fn(), | ||
disabled: false | ||
}; | ||
const result = renderHook(() => useSafeButtonProps(props)).result.current; | ||
|
||
expect(result.disabled).toBe(false); | ||
|
||
result.onClick({} as any); | ||
result.onSubmit({} as any); | ||
|
||
expect(props.onClick).toHaveBeenCalledTimes(1); | ||
expect(props.onSubmit).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('disabled trusty should not execute events', () => { | ||
const props = { | ||
onClick: jest.fn(), | ||
onSubmit: jest.fn(), | ||
disabled: true | ||
}; | ||
const result = renderHook(() => useSafeButtonProps(props)).result.current; | ||
|
||
expect(result.disabled).toBe(true); | ||
|
||
result.onClick({} as any); | ||
result.onSubmit({} as any); | ||
|
||
expect(props.onClick).toHaveBeenCalledTimes(0); | ||
expect(props.onSubmit).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it('should return props', () => { | ||
const props = { | ||
onClick: jest.fn(), | ||
onSubmit: jest.fn(), | ||
disabled: false | ||
}; | ||
|
||
const result = renderHook(() => useSafeButtonProps(props)).result.current; | ||
|
||
expect(result).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import type { ButtonEvent, ButtonEventHandler } from '@/types'; | ||
|
||
export default function useSafeButtonProps({ | ||
onClick, | ||
onSubmit, | ||
...props | ||
}: React.ComponentPropsWithoutRef<'button'>) { | ||
const wrapper = useCallback( | ||
(callback: ButtonEventHandler, event: ButtonEvent) => { | ||
!props.disabled && callback(event); | ||
}, | ||
[props.disabled] | ||
); | ||
|
||
const handleClick = useCallback( | ||
(event: ButtonEvent) => { | ||
onClick && wrapper(onClick, event); | ||
}, | ||
[onClick, wrapper] | ||
); | ||
|
||
const handleSubmit = useCallback( | ||
(event: ButtonEvent) => { | ||
onSubmit && wrapper(onSubmit, event); | ||
}, | ||
[onSubmit, wrapper] | ||
); | ||
|
||
return { | ||
...props, | ||
onClick: handleClick, | ||
onSubmit: handleSubmit | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
export * from '@/helpers'; | ||
|
||
export * from '@/hooks'; | ||
|
||
export * from '@/theme'; | ||
|
||
export * from '@/ui/components'; | ||
export * from '@/ui/forms'; | ||
export * from '@/ui/provider'; | ||
|
||
export type * from '@/types'; | ||
|
||
export * from '@/utils'; | ||
|
||
export type * from '@/types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
.button { | ||
@apply btn; | ||
|
||
&-link { | ||
@apply btn-link; | ||
} | ||
|
||
&-outline { | ||
@apply btn-outline; | ||
} | ||
|
||
&-color { | ||
&-neutral { | ||
@apply btn-neutral; | ||
} | ||
|
||
&-primary { | ||
@apply btn-primary; | ||
} | ||
|
||
&-secondary { | ||
@apply btn-secondary; | ||
} | ||
|
||
&-accent { | ||
@apply btn-accent; | ||
} | ||
|
||
&-success { | ||
@apply btn-success; | ||
} | ||
|
||
&-warning { | ||
@apply btn-warning; | ||
} | ||
|
||
&-info { | ||
@apply btn-info; | ||
} | ||
|
||
&-error { | ||
@apply btn-error; | ||
} | ||
} | ||
|
||
&-size { | ||
&-lg { | ||
@apply btn-lg; | ||
} | ||
|
||
&-sm { | ||
@apply btn-sm; | ||
} | ||
|
||
&-xs { | ||
@apply btn-xs; | ||
} | ||
} | ||
|
||
&:focus, | ||
&:hover, | ||
&:active { | ||
@apply btn-active; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './ui/base'; | ||
export * from './ui/components'; | ||
export * from './ui/forms'; | ||
export type * from './ui/base'; | ||
export type * from './ui/components'; | ||
export type * from './ui/forms'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type ButtonEvent = React.MouseEvent<HTMLButtonElement, MouseEvent>; | ||
export type ButtonEventHandler = React.MouseEventHandler<HTMLButtonElement>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export type * from './constants.types'; | ||
export type * from './dom.types'; | ||
export type * from './error.types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { ColorButtonType, SizeType } from '@/types'; | ||
import type { IconType } from 'react-icons'; | ||
import type { PositionType } from '@/types'; | ||
|
||
export interface ButtonType | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
isLink?: boolean; | ||
color?: ColorButtonType; | ||
outline?: boolean; | ||
|
||
size?: SizeType; | ||
icon?: IconType; | ||
iconPosition?: PositionType; | ||
} | ||
|
||
export type ButtonRef = HTMLButtonElement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
import { AvatarType } from './avatar.types'; | ||
|
||
export type { AvatarType }; | ||
export type * from './avatar.types'; | ||
export type * from './button.types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.