Skip to content

Commit

Permalink
chore: nova propriedade "color" nos botões
Browse files Browse the repository at this point in the history
  • Loading branch information
erikfig committed Sep 12, 2024
1 parent efa87a2 commit cda39f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/components/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { ReactNode, HTMLAttributes, HTMLProps, createElement } from 'react'
export type ButtonProps = HTMLAttributes<HTMLButtonElement> & HTMLProps<HTMLAnchorElement> & {
children?: ReactNode,
type?: "button" | "submit" | "reset",
color?: string,
}

export const Button = ({ children, className, ...props }: ButtonProps) => {
export const Button = ({ children, className, color, ...props }: ButtonProps) => {
let tag = 'button'
let localClassName = 'text-white bg-primary hover:bg-dark font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 transition-all duration-300'
let localClassName = 'text-white hover:bg-dark font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 transition-all duration-300'

if (props.href) {
tag = 'a'
Expand All @@ -17,5 +18,7 @@ export const Button = ({ children, className, ...props }: ButtonProps) => {
localClassName = `${localClassName} ${className}`
}

localClassName = `${localClassName} ${color ? color : `bg-primary`}`

return createElement(tag, { ...props, className: localClassName }, children)
}
15 changes: 13 additions & 2 deletions src/pages/forms.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useCallback, useState } from 'react'
import { Button } from '../components/button'
import { Card } from '../components/card'
import { FormContainer } from '../components/form/form-container'
Expand All @@ -17,6 +17,17 @@ export const Forms = () => {

const { handleOnChange, handleOnChangeMultiple } = useOnChange<typeof formData>(formData, setFormData)

const reset = useCallback(() => {
setFormData({
'input-password': null,
'input-text-checkbox': null,
'input-text-radio': null,
'input-text-toggle': null,
'input-text-select': null,
'input-text-select-multiple': null,
})
}, [formData])

return (
<Card>
<FormContainer>
Expand Down Expand Up @@ -154,7 +165,7 @@ export const Forms = () => {

<div>
<Button>Confirm button</Button>
<Button type="reset" className="bg-gray-500 hover:bg-dark">Reset button</Button>
<Button type="reset" color="bg-gray-600" onClick={reset}>Reset button</Button>
</div>
</FormContainer>
</Card>
Expand Down

0 comments on commit cda39f2

Please sign in to comment.