Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -501,11 +501,12 @@ const ExampleMessageText = memo<Pick<Props, 'exampleMessage'> & { managedHtmlFor
<Text
as="p"
color="TEXT_GREY"
italic
id={`${managedHtmlFor}_exampleMessage`}
className="smarthr-ui-FormControl-exampleMessage"
>
{exampleMessage}
<Text as="i" italic={false}>
{exampleMessage}
</Text>
</Text>
) : null,
)
Expand Down
20 changes: 17 additions & 3 deletions packages/smarthr-ui/src/components/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ type StyleType =
| 'subBlockTitle'
| 'subSubBlockTitle'

export const STYLE_TYPE_MAP: { [key in StyleType]: VariantProps<typeof classNameGenerator> } = {
export const STYLE_TYPE_MAP: {
[key in StyleType]: Omit<VariantProps<typeof classNameGenerator>, 'italic'>
} = {
screenTitle: {
size: 'XL',
leading: 'TIGHT',
Expand Down Expand Up @@ -61,6 +63,9 @@ const classNameGenerator = tv({
},
italic: {
true: 'shr-italic',
false: 'shr-not-italic',
// tailwind-variantsの仕様でundefinedがfalseとして扱われてしまうため、italicがundefinedの場合空文字にするためのフォールバック
undefined: '',
},
color: {
TEXT_BLACK: 'shr-text-black',
Expand All @@ -84,16 +89,25 @@ const classNameGenerator = tv({
'pre-wrap': 'shr-whitespace-pre-wrap',
},
},
defaultVariants: {
italic: 'undefined',
},
})

// VariantProps を使うとコメントが書けない〜🥹
export type TextProps<T extends ElementType = 'span'> = VariantProps<typeof classNameGenerator> & {
// italicはtailwind-variantsの仕様でundefinedがfalseとして扱われるのを回避するワークアラウンドの都合でTextPropsで再定義している
export type TextProps<T extends ElementType = 'span'> = Omit<
VariantProps<typeof classNameGenerator>,
'italic'
> & {
/** テキストコンポーネントの HTML タグ名。初期値は span */
as?: T
/** 強調するかどうかの真偽値。指定すると em 要素になる */
emphasis?: boolean
/** 見た目の種類 */
styleType?: StyleType
/** 斜体にするかどうかの真偽値 */
italic?: boolean
Comment on lines +109 to +110
Copy link
Contributor

Choose a reason for hiding this comment

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

italic にしたい時は className で渡すでも良さそうに思って、as="i" の時のデフォルトスタイルを定義しておくのはどうかしら。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

あ〜 いいかもしれないですね、日本語主体のSmartHRではitalicはそもそも使わないはずという立場にたてる気がしたので良い気がしました!

}

const ActualText = <T extends ElementType = 'span'>({
Expand All @@ -119,7 +133,7 @@ const ActualText = <T extends ElementType = 'span'>({
weight: weight || styleTypeValues.weight,
color: color || styleTypeValues.color,
leading: leading || styleTypeValues.leading,
italic,
italic: italic ?? 'undefined',
whiteSpace,
className,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { Meta, StoryObj } from '@storybook/react'

const asOptions = { なし: undefined, '<p>': 'p', '<h1>': 'h1' }

const italicOptions = { なし: undefined, true: true, false: false }

export default {
title: 'Components/Text',
component: Text,
Expand All @@ -15,10 +17,15 @@ export default {
options: Object.keys(asOptions),
mapping: asOptions,
},
italic: {
control: 'radio',
options: Object.keys(italicOptions),
mapping: italicOptions,
},
},
args: {
children: 'well-working 労働にまつわる社会課題をなくし、誰もがその人らしく働ける社会をつくる。',
italic: false,
italic: 'なし',
emphasis: false,
as: 'なし',
},
Expand Down
Loading