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: ErrorScreen, SideMenu, FlashMessage, FloatArea, FormControlの内部ロジックを整理する #5435

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

AtsushiM
Copy link
Member

@AtsushiM AtsushiM commented Mar 5, 2025

関連URL

概要

変更内容

確認方法

@AtsushiM AtsushiM changed the title chore: Fix format class name generator 7 chore: ErrorScreen, SideMenu, FlashMessage, FloatArea, FormControlの内部ロジックを整理する Mar 5, 2025
@yagimushi yagimushi force-pushed the fix-format-class-name-generator-7 branch from e2c0792 to 72ae897 Compare March 5, 2025 06:18
Copy link

pkg-pr-new bot commented Mar 5, 2025

Open in Stackblitz

npm i https://pkg.pr.new/kufu/smarthr-ui@5435

commit: 78525a1

@yagimushi yagimushi force-pushed the fix-format-class-name-generator-7 branch from db4f2b9 to 72ae897 Compare March 5, 2025 07:08
@@ -64,8 +61,8 @@ export const ErrorScreen: FC<Props & ElementProps> = ({
{links.map((link, index) => (
<li key={index}>
<TextLink
{...(link.target ? { target: link.target } : {})}
Copy link
Member Author

Choose a reason for hiding this comment

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

Object化して再展開する理由がないため、そのまま設定するようにしました

Comment on lines 61 to 68
const GroupTitleText = memo<PropsWithChildren<{ titleElementAs?: ElementType; className: string }>>(
({ titleElementAs: Component = 'p', children, className }) => (
<Component>
<Text color="TEXT_BLACK" leading="TIGHT" size="S" weight="bold" className={className}>
{children}
</Text>
</Component>
),
Copy link
Member Author

Choose a reason for hiding this comment

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

一度レンダリングされれば変更が必要になる可能性がかなり低いためmemo化しています

export const FlashMessage: FC<Props & ElementProps> = ({
visible,
export const FlashMessage: FC<ActualProps> = ({ visible, ...rest }) =>
visible ? <ActualFlashMessage {...rest} /> : null
Copy link
Member Author

Choose a reason for hiding this comment

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

visibleがtrueにならない限り、あらゆる判定が不要なため、コンポーネントを切り分け、hookの実行を条件分岐できるようにしました

Comment on lines -44 to -49
type StyleProps = {
/** コンポーネントの下端から、包含ブロックの下端までの間隔(基準フォントサイズの相対値または抽象値) */
bottom?: CharRelativeSize | AbstractSize
/** コンポーネントの `z-index` 値 */
zIndex?: number
}
Copy link
Member Author

Choose a reason for hiding this comment

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

StylePropsは直後に結合される以外で利用されていないため、分割されている意味が薄い状態でした

Copy link
Collaborator

Choose a reason for hiding this comment

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

imo: 振る舞いに必要な props とスタイリングでしか使わない props で別れてるのは、見方によれば有用だと思います。

Copy link
Member Author

@AtsushiM AtsushiM Mar 6, 2025

Choose a reason for hiding this comment

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

@uknmr

imo: 振る舞いに必要な props とスタイリングでしか使わない props で別れてるのは、見方によれば有用だと思います。

まぁそうなんですが、他コンポーネントで同様の理由で別れているものはないためこのコンポーネントで別れていると 再利用されているのか? などの疑念が生じる可能性もあるし、まとめちゃうほうがいいかなーと思っています。
(もちろん複数回利用されている場合などで分割されているものは良いと思います)

Copy link
Collaborator

Choose a reason for hiding this comment

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

再利用されているのか? と同じように、変更後では「これどこで使われてるの? スタイルだけだっ!」なるので、何を取るかだと思います。
特に方針がないので現状のままで良いのではと思いました。

Copy link
Member Author

@AtsushiM AtsushiM Mar 6, 2025

Choose a reason for hiding this comment

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

これどこで使われてるの? スタイルだけだっ!

なるほど?
いや、でもそれ型で制限できない概念ですよね?
(例: StylePropsに書いたからtvに食わせる箇所でしかその属性を利用出来ないわけではない)

特定の値がどこで使われているかを確認できるのは、実際に利用されている箇所を確認するしかないですし、型があることで↑で書かれているような利用がされてしまうのは逆に問題だと思います。

例えば何らかの修正を行う人が対象属性をスタイル以外に利用する際、StlylePropsから移動しないと概念が崩れてしまうことになるし、それらの食い違いが発生する方法を防ぐ仕組みは現在有りません。

これらの問題を事前に防ぐために、むしろまとめるべきだと思います。

Copy link
Collaborator

Choose a reason for hiding this comment

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

修正の正しさを議論したいわけではなく、明確な指針や成果のない修正は入れなくていいのでは? と思ってます。

Copy link
Member Author

@AtsushiM AtsushiM Mar 9, 2025

Choose a reason for hiding this comment

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

修正の正しさを議論したいわけではなく、明確な指針や成果のない修正は入れなくていいのでは? と思ってます。

この意見に関して、完全に反対します。
明確な指針、成果は↑で言っている通り

  • 分割されている意味が薄く理由がわからない
  • 分割されていることで発生するデメリットがある(かん違いが発生する可能性があり、かつそれを防げない)
  • 他コンポーネントで同様のことをしている箇所が(少なくとも私が知っている範囲で)ない

です。
この箇所は現時点で 他で採用されていない状態になっており、それによって発生するメリットは実装を見ないと本当かどうか分からないためイマイチ、かつ修正時に見過ごされる可能性がある状態になっており、かつ簡単に修正できる箇所 です。

はっきり言ってしまえば 当たり前のイディオム・指針から外れている状態 だと考えています。
すべて正しい状態にしろ!とは言いませんし、思いませんし、実際不可能ですが、気づいたタイミングで治すべきでは?(型のマージだけでコストほぼかからないですし)

そもそもこの議論の箇所のような型の分割を許容すると至る所で型が分割されかねません。
exportしていたり、複数箇所で参照されるなど、以外で型が分割されていると 型と型をmergeして考える 必要が発生し、開発者の短期記憶に負荷がかかります。

  • 型と型をmergeして考える必要が発生する
  • どの型に記述するべきか検討する必要が発生する

などです。
これは望むところではないのでは?

Copy link
Member Author

@AtsushiM AtsushiM Mar 9, 2025

Choose a reason for hiding this comment

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

またStylePropsの発生タイミングなどを確認しました

370ce97#diff-7390611a4783fb92a84ad63fad0535413ffda21bd090e5b177cb1c1523dad84bR12-R26

この型は FloatArea と過去存在していた内部コンポーネントの Base で同じ部分を共通化するための型という意図だと思われます。
おそらくその後、内部のBaseコンポーネントの削除時、そのまま放置されてきただけです。

Copy link
Collaborator

Choose a reason for hiding this comment

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

改善しようとしているのはわかるんですが、不要なところにも手を入れてレビューする側のコストが上がってるように感じます。
議論コストも高いので、ここで細かな話をする気はないです。
指針を決めるような動き方をしていただければ、何の問題もないです。

Copy link
Member Author

Choose a reason for hiding this comment

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

指針を決めるような動き方をしていただければ、何の問題もないです。

↑で言っている通り、これは 当たり前のイディオム・指針から外れている状態 だと思っているので、そこの指針を本当に決めますか?
何もかも指針を決めることになりかねないと感じており、個人的にはそこまでやりたくないのですが...

Comment on lines -295 to -296
errorListStyle={errorListStyle}
errorIconStyle={errorIconStyle}
Copy link
Member Author

Choose a reason for hiding this comment

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

これらの値はclassNamesにまとめられており、変化する場合は両方同時に変化するため、classNamesをそのまま渡すほうが処理として最適です

@AtsushiM AtsushiM marked this pull request as ready for review March 5, 2025 23:58
@AtsushiM AtsushiM requested a review from a team as a code owner March 5, 2025 23:58
@AtsushiM AtsushiM requested review from Qs-F and uknmr and removed request for a team March 5, 2025 23:58
Comment on lines -44 to -49
type StyleProps = {
/** コンポーネントの下端から、包含ブロックの下端までの間隔(基準フォントサイズの相対値または抽象値) */
bottom?: CharRelativeSize | AbstractSize
/** コンポーネントの `z-index` 値 */
zIndex?: number
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

imo: 振る舞いに必要な props とスタイリングでしか使わない props で別れてるのは、見方によれば有用だと思います。

@AtsushiM AtsushiM requested a review from uknmr March 6, 2025 03:01
AtsushiM and others added 2 commits March 6, 2025 13:41
…enuGroup.tsx

Co-authored-by: KANAMORI Yu <y.kinmori@gmail.com>
@AtsushiM
Copy link
Member Author

AtsushiM commented Mar 6, 2025

@uknmr
ちょっと調べた感じ、titleElementAs、listElementA、ともに利用されている箇所がないんですが、この属性って必要なんですっけ?
https://github.com/search?q=org%3Akufu%20SideMenuGroup&type=code

あってもいいと思うんですが、Section > Headingの構造にしたりする場合、ちょっと面倒な気がしており...

@yagimushi yagimushi force-pushed the fix-format-class-name-generator-7 branch from 1e158df to 78525a1 Compare March 6, 2025 22:52
@AtsushiM
Copy link
Member Author

AtsushiM commented Mar 6, 2025

マークアップから変更してみました
78525a1

Copy link
Collaborator

@uknmr uknmr left a comment

Choose a reason for hiding this comment

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

titleElementAs、listElementA、ともに利用されている箇所がないんですが、この属性って必要なんですっけ

ul を dl として使いたい、p ではなく heading にしたい用途かな、なのであっても良さそうだけど、Heading が使いにくくなるのはわかる。

<Text color="TEXT_BLACK" leading="TIGHT" size="S" weight="bold" className={groupTitleStyle}>
<li className={classNames.wrapper}>
<Section>
<GroupHeading titleElementAs={titleElementAs} className={classNames.groupTitle}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

コンポーネントとしてはナビゲーションで、コンテンツ領域に同名の Heading がつくのでマークアップは元のままで良いと思います。

Copy link
Member Author

@AtsushiM AtsushiM Mar 9, 2025

Choose a reason for hiding this comment

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

ul を dl として使いたい

型としては ul, ol しか許容していないですね。
あれな話、ul <-> ol しか出来ないなら、使い勝手悪そう...
(そして内部的にliが使われているので、この属性の型としては正しい)

Copy link
Member Author

Choose a reason for hiding this comment

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

コンポーネントとしてはナビゲーションで、コンテンツ領域に同名の Heading がつくのでマークアップは元のままで良いと思います。

これの意味がイマイチわかっていないのですが、SideMenuGroupの使い方って以下の感じですよね?
Headingはついていないきがします 🤔

<SideMenu>
  <SideMenuGroup title="個人設定">
    <SideMenuItem href="#">アカウント</SideMenuItem>
    <SideMenuItem href="#" current>
      認証設定
    </SideMenuItem>
  </SideMenuGroup>
</SideMenu>

Copy link
Member Author

Choose a reason for hiding this comment

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

あ、これに対応するコンテンツがあり、そちらにHeadingがあるからこっちはHeadingにする必要ないやろ、ってことですかね?

Copy link
Member Author

@AtsushiM AtsushiM Mar 9, 2025

Choose a reason for hiding this comment

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

↑だとしたら、ややこしいな...
ざっと調べたんですがSideMenuは基本的にナビゲーションということもあり、Nav 要素でマークアップしてしまえば、内部でHeading使ってもいいんじゃないかなーと思いました。
明確にナビゲーション内の見出しということが伝わるし... (むしろ現状Navじゃないんや)

ぱっと見た感じ、dl > dt, dd 構造にしたくなるけど、SideMenuGroupつかわない場合も考慮するとNav > Section > Heading, ul構造がいいんじゃないかなーと思っています

SideMenuGroupを使わない場合は Nav > ul 構造にできるし。

Copy link
Collaborator

Choose a reason for hiding this comment

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

nav > ul > li > p これが「個人設定」
nav > ul > li > ul > li > p これが「アカウント」
で、構造をあらわせてないですか?

Copy link
Member Author

@AtsushiM AtsushiM Mar 10, 2025

Choose a reason for hiding this comment

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

@uknmr さんの言っている構造を表せている、がなんのことかイマイチわかっていませんが俺は

  • 個人設定アカウント が何らかの見出しであるべきでは?それにはpよりheadingやdtが良いのでは?

という話をしているのであって、併せて

  • pとulなどが並んでいてもpはulの見出しにはならないですよね?

という話をしています。
個人設定アカウントが見出しである、という認識が揃っているならなぜ pの方が良いと思っているのかが知りたく。

uさんの意見は極論すると 階層構造を持ったSectioningContentはSectioningContentで表す必要がなく、全部pで見出しつけてもいい と言っているように読解してしまうんですが違いますよね?

コンポーネント思考と同じで、この部分だけで切り出して考えるべきな気がしており、 ここは見出し と思われるならそれに適した要素でマークアップするべきでは?というのが俺の意見です。

Copy link
Collaborator

Choose a reason for hiding this comment

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

私はナビゲーションとしての役割の話をしていて、smarthr-ui で言えば

  • AppHeader
  • AppNavi
  • TabBar
  • Pagination

などのコンポーネントで li の中身が見出しになっている必要を感じたことがないし、慣習的にも見かけてないです。

Copy link
Member Author

@AtsushiM AtsushiM Mar 11, 2025

Choose a reason for hiding this comment

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

TabBarとPaginationはそもそもリンク、もしくはボタンに当たる部分しかないので今回の議論から除外していいと思います。

AppNaviに関して言えば機能名に当たる部分はHeadingですが、liに当たる部分にリンク、ボタン以外が存在しないのでこれも議論の対象外でいいと思います。
https://smarthr.design/products/components/app-navi/

AppHeaderはそもそもnavやul, liが使われていないため、参照するのは微妙な気もしますが、例えばドロップダウンを開いた後の 勤怠管理 管理メニュー などは見出しになっています
(AccordionPanelが使われていそうですね)

https://smarthr.design/products/components/app-header/

コンポーネントで li の中身が見出しになっている必要を感じたことがないし、慣習的にも見かけてないです。

私はありますし、ナビゲーション内で見出しをつけること自体は大きなナビゲーションを実装する場合、割とポピュラーでは...?
例えばamazonなどはdivにroleを指定する形ですが明確にheadingを利用しています。
範囲指定などを考慮されていないため、マークアップとしては微妙かもしれませんが...
スクリーンショット 2025-03-11 15 30 07

Copy link
Member Author

@AtsushiM AtsushiM Mar 11, 2025

Choose a reason for hiding this comment

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

smarthr内部の例だとトップページに当たる部分では、navが分割されていますが、これも検討の一助にはなりそうです。
(この例の場合、そもそもnav分割しないほうが良さそうな気がします)
スクリーンショット 2025-03-11 15 38 34
スクリーンショット 2025-03-11 15 45 13

@AtsushiM AtsushiM requested a review from uknmr March 10, 2025 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants