Skip to content

Commit

Permalink
feat: Aside component
Browse files Browse the repository at this point in the history
  • Loading branch information
NyctibiusVII committed May 3, 2023
1 parent 89c25bc commit 1faac24
Show file tree
Hide file tree
Showing 6 changed files with 467 additions and 293 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
"postcss": "8.4.23",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "^4.8.0",
"tailwindcss": "3.3.1",
"typescript": "5.0.4"
"typescript": "5.0.4",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/dom-to-image": "^2.6.4"
"@types/dom-to-image": "^2.6.4",
"@types/uuid": "^9.0.1"
}
}
35 changes: 35 additions & 0 deletions src/components/details/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useEffect, useState } from 'react'
import { v4 as uuid } from 'uuid'

interface DetailsProps {
children: React.ReactNode
summary?: string
}

export const Details = ({ summary = 'Title', children }: DetailsProps) => {
const [detailsOpen, setDetailsOpen] = useState(false)
const [detailsId, setDetailsId] = useState('')

useEffect(() => setDetailsId(uuid()), [])

useEffect(() => {
const details = document.querySelector(`details[data-details-id="${detailsId}"]`) as HTMLDetailsElement
if (!details) return

const handleToggle = () => setDetailsOpen(details.open)
details.addEventListener('toggle', handleToggle)

return () => details.removeEventListener('toggle', handleToggle)
}, [detailsId])

return (
<details data-details-id={detailsId} open={detailsOpen} className='cursor-pointer'>
<summary className={`bg-gray-800 ${detailsOpen ? 'rounded-t-lg' : 'rounded-lg'} px-4 py-1`}>
{summary}
</summary>
<div className='bg-gray-700 rounded-b-lg px-4 py-1'>
{children}
</div>
</details>
)
}
28 changes: 26 additions & 2 deletions src/components/form/input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
import { useEffect, useRef } from 'react'
import { useField } from '@unform/core'

import { InputProps } from "@/interfaces/types"
import { InputProps } from '@/interfaces/types'

export const Input = ({ name, label, labelPosition='before', container=false, ...props }: InputProps) => {
export const Input = ({ withForm=true, ...props }: InputProps) => withForm ? <UnFormInput {...props}/> : <InputComponent {...props}/>

const InputComponent = ({ name, label, labelPosition='before', container=false, className, ...props }: InputProps) => {
const Input = <input className={`inputNumberValues border border-dashed rounded-lg pl-1 ${className}`} {...props}/>
const Label = <label htmlFor={name} className='max-w-[13rem]'>{label}</label>

return <>{ container ?
<div className={'flex flex-nowrap gap-1'}>
{
(label && labelPosition === 'after') && <>{Input}{Label}</>
||
(label) && <>{Label}{Input}</>
|| Input
}
</div>
:
<>{
(label && labelPosition === 'after') && <>{Input}{Label}</>
||
(label) && <>{Label}{Input}</>
|| Input
}</>
}</>
}
const UnFormInput = ({ name, label, labelPosition='before', container=false, ...props }: InputProps) => {
const inputRef = useRef<HTMLInputElement>(null)
const {
fieldName,
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type InputType = {
label?: string
labelPosition?: 'before' | 'after'
container?: boolean
withForm?: boolean
}
/**
* Defines the types of native input properties.
Expand Down
Loading

1 comment on commit 1faac24

@vercel
Copy link

@vercel vercel bot commented on 1faac24 May 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.