Fix line endings
This commit is contained in:
parent
004dd7168e
commit
e712a054ae
|
@ -1,31 +1,31 @@
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
|
|
||||||
export function Checkbox(props: {
|
export function Checkbox(props: {
|
||||||
label: string
|
label: string
|
||||||
checked: boolean
|
checked: boolean
|
||||||
toggle: (checked: boolean) => void
|
toggle: (checked: boolean) => void
|
||||||
className?: string
|
className?: string
|
||||||
}) {
|
}) {
|
||||||
const { label, checked, toggle, className } = props
|
const { label, checked, toggle, className } = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={clsx(className, 'space-y-5')}>
|
<div className={clsx(className, 'space-y-5')}>
|
||||||
<div className="relative flex items-start">
|
<div className="relative flex items-start">
|
||||||
<div className="flex h-6 items-center">
|
<div className="flex h-6 items-center">
|
||||||
<input
|
<input
|
||||||
id={label}
|
id={label}
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="h-5 w-5 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
|
className="h-5 w-5 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
|
||||||
checked={checked}
|
checked={checked}
|
||||||
onChange={(e) => toggle(!e.target.checked)}
|
onChange={(e) => toggle(!e.target.checked)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-3">
|
<div className="ml-3">
|
||||||
<label htmlFor={label} className="font-medium text-gray-700">
|
<label htmlFor={label} className="font-medium text-gray-700">
|
||||||
{label}
|
{label}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
// A hook soon to be added to the React core library:
|
// A hook soon to be added to the React core library:
|
||||||
// https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
|
// https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
|
||||||
// TODO: Once React adds this hook, use it instead.
|
// TODO: Once React adds this hook, use it instead.
|
||||||
|
|
||||||
import { useRef, useLayoutEffect, useCallback } from 'react'
|
import { useRef, useLayoutEffect, useCallback } from 'react'
|
||||||
|
|
||||||
type AnyFunction = (...args: any[]) => any
|
type AnyFunction = (...args: any[]) => any
|
||||||
|
|
||||||
export function useEvent<T extends AnyFunction>(callback?: T) {
|
export function useEvent<T extends AnyFunction>(callback?: T) {
|
||||||
const ref = useRef<AnyFunction | undefined>(() => {
|
const ref = useRef<AnyFunction | undefined>(() => {
|
||||||
throw new Error('Cannot call an event handler while rendering.')
|
throw new Error('Cannot call an event handler while rendering.')
|
||||||
})
|
})
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
ref.current = callback
|
ref.current = callback
|
||||||
})
|
})
|
||||||
return useCallback<AnyFunction>(
|
return useCallback<AnyFunction>(
|
||||||
(...args) => ref.current?.apply(null, args),
|
(...args) => ref.current?.apply(null, args),
|
||||||
[]
|
[]
|
||||||
) as T
|
) as T
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user