Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: AppNavi, BottomFixedArea, MultiComboboxの内部処理を整理する #5441

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { tv } from 'tailwind-variants'
import { ElementRef, ElementRefProps } from '../../types'
import { ComponentProps as IconProps } from '../Icon'

import { appNaviItemStyle } from './style'
import { itemClassNameGenerator } from './itemClassNameGenerator'

type ElementProps<T extends ElementType> = Omit<
ComponentPropsWithoutRef<T>,
Expand All @@ -37,7 +37,7 @@ type AppNaviAnchorComponent = <T extends ElementType = 'a'>(
) => ReturnType<FC>

const classNameGenerator = tv({
extend: appNaviItemStyle,
extend: itemClassNameGenerator,
slots: {
wrapper: ['smarthr-ui-AppNavi-anchor', 'forced-colors:shr-underline'],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tv } from 'tailwind-variants'
import { UnstyledButton } from '../Button'
import { ComponentProps as IconProps } from '../Icon'

import { appNaviItemStyle } from './style'
import { itemClassNameGenerator } from './itemClassNameGenerator'

export type AppNaviButtonProps = PropsWithChildren<{
/** 表示するアイコンタイプ */
Expand All @@ -16,7 +16,7 @@ export type AppNaviButtonProps = PropsWithChildren<{
}>

const classNameGenerator = tv({
extend: appNaviItemStyle,
extend: itemClassNameGenerator,
slots: {
wrapper: 'smarthr-ui-AppNavi-button',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { tv } from 'tailwind-variants'

import { ComponentProps as IconProps } from '../Icon'

import { appNaviItemStyle } from './style'
import { itemClassNameGenerator } from './itemClassNameGenerator'

export type AppNaviCustomTagProps = PropsWithChildren<{
/** このボタンのカスタムタグ */
Expand All @@ -15,7 +15,7 @@ export type AppNaviCustomTagProps = PropsWithChildren<{
}> & { [key: string]: any }

const classNameGenerator = tv({
extend: appNaviItemStyle,
extend: itemClassNameGenerator,
slots: {
wrapper: 'smarthr-ui-AppNavi-customTag',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UnstyledButton } from '../Button'
import { Dropdown, DropdownContent, DropdownTrigger } from '../Dropdown'
import { FaCaretDownIcon, ComponentProps as IconProps } from '../Icon'

import { appNaviItemStyle } from './style'
import { itemClassNameGenerator } from './itemClassNameGenerator'

export type AppNaviDropdownProps = PropsWithChildren<{
/** ドロップダウンのコンテンツ */
Expand All @@ -18,7 +18,7 @@ export type AppNaviDropdownProps = PropsWithChildren<{
}>

const classNameGenerator = tv({
extend: appNaviItemStyle,
extend: itemClassNameGenerator,
variants: {
displayCaret: {
true: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tv } from 'tailwind-variants'

export const appNaviItemStyle = tv({
export const itemClassNameGenerator = tv({
slots: {
wrapper: [
'shr-box-border shr-inline-flex shr-cursor-pointer shr-items-center shr-gap-0.5 shr-whitespace-nowrap shr-px-0.5 shr-py-0.75 shr-text-base shr-font-bold shr-leading-none shr-no-underline shr-text-grey',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
'use client'

import React, {
ComponentProps,
ComponentPropsWithRef,
ComponentType,
FC,
FunctionComponentElement,
MouseEventHandler,
ReactNode,
type ComponentProps,
type ComponentPropsWithRef,
type ComponentType,
type FC,
type FunctionComponentElement,
type MouseEventHandler,
type PropsWithChildren,
type ReactNode,
memo,
useEffect,
useMemo,
} from 'react'
import { tv } from 'tailwind-variants'

import { Base } from '../Base'
import { AnchorButton, Button } from '../Button'
import { ComponentProps as IconProps } from '../Icon'
import { type ComponentProps as IconProps } from '../Icon'
import { Cluster, Stack } from '../Layout'

import { validateElement } from './bottomFixedAreaHelper'
Expand Down Expand Up @@ -50,7 +52,7 @@ type Props = {
zIndex?: number
}

const bottomFixedArea = tv({
const classNameGenerator = tv({
slots: {
wrapper: [
'smarthr-ui-BottomFixedArea',
Expand Down Expand Up @@ -78,22 +80,24 @@ export const BottomFixedArea: FC<Props & ElementProps> = ({
className,
...props
}) => {
const { wrapperStyleProps, tertiaryButtonStyle } = useMemo(() => {
const { wrapper, tertiaryButton } = bottomFixedArea()
const classNames = useMemo(() => {
const { wrapper, tertiaryButton } = classNameGenerator()

return {
wrapperStyleProps: { className: wrapper({ className }), style: { zIndex } },
tertiaryButtonStyle: tertiaryButton(),
wrapper: wrapper({ className }),
tertiaryButton: tertiaryButton(),
}
}, [className, zIndex])
}, [className])
const style = useMemo(() => ({ zIndex }), [zIndex])

useEffect(() => {
validateElement(primaryButton, secondaryButton)
}, [primaryButton, secondaryButton])

return (
<Base {...props} {...wrapperStyleProps}>
<Base {...props} className={classNames.wrapper} style={style}>
<Stack>
{description && <p className="smarthr-ui-BottomFixedArea-description">{description}</p>}
<Description>{description}</Description>
<Stack gap={0.25}>
{(secondaryButton || primaryButton) && (
<Cluster as="ul" justify="center" gap={{ row: 0.5, column: 1 }}>
Expand All @@ -107,14 +111,13 @@ export const BottomFixedArea: FC<Props & ElementProps> = ({
)}
{tertiaryLinks && tertiaryLinks.length > 0 && (
<Cluster as="ul" justify="center" gap={{ row: 0.5, column: 0 }}>
{tertiaryLinks.map(({ text, icon: Icon, onClick, ...tertiaryProps }, index) => (
{tertiaryLinks.map(({ text, icon: Icon, ...tertiaryRest }, index) => (
<li key={index} className="smarthr-ui-BottomFixedArea-tertiaryListItem">
<Button
{...tertiaryProps}
{...tertiaryRest}
variant="text"
prefix={Icon && <Icon />}
onClick={onClick}
className={tertiaryButtonStyle}
className={classNames.tertiaryButton}
>
{text}
</Button>
Expand All @@ -127,3 +130,8 @@ export const BottomFixedArea: FC<Props & ElementProps> = ({
</Base>
)
}

const Description = memo<PropsWithChildren>(
({ children }) =>
children && <p className="smarthr-ui-BottomFixedArea-description">{children}</p>,
)
Comment on lines +130 to +133
Copy link
Member Author

Choose a reason for hiding this comment

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

descriptionが変化する可能性は低いため、memo化しています

Loading