Skip to content

Commit

Permalink
chore: 独自実装の useId を削除する
Browse files Browse the repository at this point in the history
  • Loading branch information
s-sasaki-0529 committed Sep 17, 2024
1 parent 28e590e commit 8d8c962
Show file tree
Hide file tree
Showing 23 changed files with 47 additions and 69 deletions.
11 changes: 9 additions & 2 deletions packages/smarthr-ui/src/components/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import dayjs from 'dayjs'
import React, { ComponentProps, MouseEvent, forwardRef, useEffect, useMemo, useState } from 'react'
import React, {
ComponentProps,
MouseEvent,
forwardRef,
useEffect,
useId,
useMemo,
useState,
} from 'react'
import { tv } from 'tailwind-variants'

import { useId } from '../../hooks/useId'
import { Button } from '../Button'
import { FaCaretDownIcon, FaCaretUpIcon, FaChevronLeftIcon, FaChevronRightIcon } from '../Icon'
import { Cluster } from '../Layout'
Expand Down
5 changes: 3 additions & 2 deletions packages/smarthr-ui/src/components/CheckBox/CheckBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import React, {
forwardRef,
useCallback,
useEffect,
useId,
useImperativeHandle,
useMemo,
useRef,
} from 'react'
import { tv } from 'tailwind-variants'

import { useId } from '../../hooks/useId'
import { FaCheckIcon, FaMinusIcon } from '../Icon'

export type Props = PropsWithChildren<
Expand Down Expand Up @@ -119,7 +119,8 @@ export const CheckBox = forwardRef<HTMLInputElement, Props>(
}
}, [checked, mixed])

const checkBoxId = useId(props.id)
const defaultId = useId()
const checkBoxId = props.id || defaultId

return (
<span className={wrapperStyle}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import React, {
useRef,
useState,
} from 'react'
import { useId } from 'react'
import innerText from 'react-innertext'
import { tv } from 'tailwind-variants'

import { useId } from '../../hooks/useId'
import { useOuterClick } from '../../hooks/useOuterClick'
import { useTheme } from '../../hooks/useTailwindTheme'
import { genericsForwardRef } from '../../libs/util'
Expand Down
2 changes: 1 addition & 1 deletion packages/smarthr-ui/src/components/ComboBox/useListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import React, {
RefObject,
useCallback,
useEffect,
useId,
useMemo,
useRef,
useState,
} from 'react'
import { tv } from 'tailwind-variants'

import { useEnhancedEffect } from '../../hooks/useEnhancedEffect'
import { useId } from '../../hooks/useId'
import { usePortal } from '../../hooks/usePortal'
import { useTheme } from '../../hooks/useTailwindTheme'
import { FaInfoCircleIcon } from '../Icon'
Expand Down
4 changes: 1 addition & 3 deletions packages/smarthr-ui/src/components/ComboBox/useOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useCallback, useMemo } from 'react'
import { useCallback, useId, useMemo } from 'react'
import innerText from 'react-innertext'

import { useId } from '../../hooks/useId'

import { convertMatchableString } from './comboBoxHelper'
import { ComboBoxItem, ComboBoxOption } from './types'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import React, {
forwardRef,
useCallback,
useEffect,
useId,
useImperativeHandle,
useMemo,
useRef,
useState,
} from 'react'
import { tv } from 'tailwind-variants'

import { useId } from '../../hooks/useId'
import { useOuterClick } from '../../hooks/useOuterClick'
import { useTheme } from '../../hooks/useTailwindTheme'
import { Calendar } from '../Calendar'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ComponentProps, useCallback } from 'react'
import React, { ComponentProps, useCallback, useId } from 'react'

import { useId } from '../../../hooks/useId'
import { DialogContentInner } from '../DialogContentInner'
import { DialogProps } from '../types'
import { useDialogPortal } from '../useDialogPortal'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { HTMLAttributes, useCallback, useContext } from 'react'
import React, { HTMLAttributes, useCallback, useContext, useId } from 'react'

import { useId } from '../../../hooks/useId'
import { DialogContentInner } from '../DialogContentInner'
import { DialogContext } from '../DialogWrapper'
import { UncontrolledDialogProps } from '../types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ReactElement, cloneElement, useCallback, useMemo, useState } from 'react'
import React, { ReactElement, cloneElement, useCallback, useId, useMemo, useState } from 'react'

import { useId } from '../../../hooks/useId'
import { ActionDialog } from '../ActionDialog'

type ToggleModalActionType = () => void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ComponentProps, FormEvent, useCallback } from 'react'
import React, { ComponentProps, FormEvent, useCallback, useId } from 'react'

import { useId } from '../../../hooks/useId'
import { DialogContentInner } from '../DialogContentInner'
import { DialogProps } from '../types'
import { useDialogPortal } from '../useDialogPortal'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { FormEvent, HTMLAttributes, useCallback, useContext } from 'react'
import React, { FormEvent, HTMLAttributes, useCallback, useContext, useId } from 'react'

import { useId } from '../../../hooks/useId'
import { DialogContentInner } from '../DialogContentInner'
import { DialogContext } from '../DialogWrapper'
import { UncontrolledDialogProps } from '../types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ComponentProps, useCallback } from 'react'
import React, { ComponentProps, useCallback, useId } from 'react'

import { useId } from '../../../hooks/useId'
import { DialogContentInner } from '../DialogContentInner'
import { DialogProps } from '../types'
import { useDialogPortal } from '../useDialogPortal'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ComponentProps, useCallback, useContext } from 'react'
import React, { ComponentProps, useCallback, useContext, useId } from 'react'

import { useId } from '../../../hooks/useId'
import { DialogContentInner } from '../DialogContentInner'
import { DialogContext } from '../DialogWrapper'
import { UncontrolledDialogProps } from '../types'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, {
RefObject,
useCallback,
useEffect,
useId,
useMemo,
useRef,
useState,
Expand All @@ -15,7 +16,6 @@ import Draggable from 'react-draggable'
import { VariantProps, tv } from 'tailwind-variants'

import { useHandleEscape } from '../../hooks/useHandleEscape'
import { useId } from '../../hooks/useId'
import { useTheme } from '../../hooks/useTailwindTheme'
import { Base, BaseElementProps } from '../Base'
import { Button } from '../Button'
Expand Down
2 changes: 1 addition & 1 deletion packages/smarthr-ui/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import React, {
createContext,
useContext,
useEffect,
useId,
useMemo,
useRef,
useState,
} from 'react'

import { useId } from '../../hooks/useId'
import { usePortal } from '../../hooks/usePortal'

import { Rect, getFirstTabbable, isEventFromChild } from './dropdownHelper'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import React, {
useMemo,
useRef,
} from 'react'
import { useId } from 'react'
import { isStyledComponent } from 'styled-components'
import { tv } from 'tailwind-variants'

import { useId } from '../../hooks/useId'
import { MultiComboBox, SingleComboBox } from '../ComboBox'
import { DatePicker } from '../DatePicker'
import { DropZone } from '../DropZone'
Expand Down Expand Up @@ -146,8 +146,10 @@ export const ActualFormControl: React.FC<Props & ElementProps> = ({
children,
...props
}) => {
const managedHtmlFor = useId(htmlFor)
const managedLabelId = useId(labelId)
const defaultHtmlFor = useId()
const defaultLabelId = useId()
const managedHtmlFor = htmlFor || defaultHtmlFor
const managedLabelId = labelId || defaultLabelId
const inputWrapperRef = useRef<HTMLDivElement>(null)
const isRoleGroup = as === 'fieldset'
const statusLabelList = Array.isArray(statusLabelProps) ? statusLabelProps : [statusLabelProps]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import React, { FC, PropsWithChildren, useCallback, useEffect, useMemo, useState } from 'react'
import React, {
FC,
PropsWithChildren,
useCallback,
useEffect,
useId,
useMemo,
useState,
} from 'react'
import { tv } from 'tailwind-variants'

import { useId } from '../../hooks/useId'
import { Base, BaseElementProps } from '../Base'
import { Button } from '../Button'
import { Heading, HeadingTagTypes } from '../Heading'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import React, {
PropsWithChildren,
forwardRef,
useCallback,
useId,
useMemo,
} from 'react'
import { tv } from 'tailwind-variants'

import { useId } from '../../hooks/useId'
import { isIOS } from '../../libs/ua'

type Props = PropsWithChildren<ComponentPropsWithRef<'input'>>
Expand Down Expand Up @@ -72,7 +72,8 @@ export const RadioButton = forwardRef<HTMLInputElement, Props>(
[onChange],
)

const radioButtonId = useId(props.id)
const defaultId = useId()
const radioButtonId = defaultId || props.id

return (
<span className={wrapperStyle}>
Expand Down
6 changes: 3 additions & 3 deletions packages/smarthr-ui/src/components/Switch/Switch.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { InputHTMLAttributes, ReactNode, forwardRef, useMemo } from 'react'
import React, { InputHTMLAttributes, ReactNode, forwardRef, useId, useMemo } from 'react'
import { tv } from 'tailwind-variants'

import { useId } from '../../hooks/useId'
import { FaCheckIcon } from '../Icon'
import { Cluster } from '../Layout'
import { Text } from '../Text'
Expand Down Expand Up @@ -56,7 +55,8 @@ export const Switch = forwardRef<HTMLInputElement, Props>(
({ children, dangerouslyLabelHidden, className, id, ...props }, ref) => {
const { wrapper, input, icon, iconWrapper } = useMemo(() => switchStyle(), [])
const ActualLabelComponent = dangerouslyLabelHidden ? VisuallyHiddenText : Text
const inputId = useId(id)
const defaultId = useId()
const inputId = id || defaultId

return (
<Cluster align="center">
Expand Down
2 changes: 1 addition & 1 deletion packages/smarthr-ui/src/components/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import React, {
startTransition,
useCallback,
useEffect,
useId,
useImperativeHandle,
useMemo,
useRef,
useState,
} from 'react'
import { tv } from 'tailwind-variants'

import { useId } from '../../hooks/useId'
import { useTheme } from '../../hooks/useTailwindTheme'
import { debounce } from '../../libs/debounce'
import { defaultHtmlFontSize } from '../../themes/createFontSize'
Expand Down
2 changes: 1 addition & 1 deletion packages/smarthr-ui/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, {
ReactElement,
ReactNode,
useCallback,
useId,
useMemo,
useRef,
useState,
Expand All @@ -15,7 +16,6 @@ import innerText from 'react-innertext'
import { tv } from 'tailwind-variants'

import { useEnhancedEffect } from '../../hooks/useEnhancedEffect'
import { useId } from '../../hooks/useId'
import { Props as BalloonProps } from '../Balloon'
import { VisuallyHiddenText } from '../VisuallyHiddenText'

Expand Down
25 changes: 0 additions & 25 deletions packages/smarthr-ui/src/hooks/useId.test.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/smarthr-ui/src/hooks/useId.tsx

This file was deleted.

0 comments on commit 8d8c962

Please sign in to comment.