Sliderの修正 - #137
Conversation
- スライダーの初期値、最大値、増減単位、無効化、向き、スタイルに関する説明を削除 - スライダーの範囲の背景色を変更 - スライダーのトラックスタイルを更新
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- スライダーの制御機能を追加し、状態管理を実装 - スライダーに単位表示を追加 - 不要なプロパティ「orientation」を削除 - スライダーのスタイルを改善
- スライダーコンポーネントの制御状態を管理するロジックを改善 - 非制御コンポーネントの内部状態管理を追加 - スライダーコンポーネントのテストケースを新規作成 - ユーザーインタラクションに関するテストを強化
- スライダーコンポーネントの説明をより具体的に修正 - Figmaとの接続設定を新規追加
- フォントの依存関係を追加
There was a problem hiding this comment.
Pull Request Overview
This PR implements improvements to the Slider component based on feedback, including disabled state fixes, value display, comprehensive test coverage, and Storybook adjustments.
- Added value indicator display with optional unit support
- Fixed disabled state styling for track, range, and thumb elements
- Added comprehensive test coverage with 503 lines of tests
- Enhanced Storybook with controlled mode and unit examples
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/setup.ts | Added ResizeObserver and MatchMedia polyfills for jsdom testing environment |
| src/components/ui/slider/item.json | Updated component description and added sparkle-font dependency |
| src/components/ui/slider/index.tsx | Major refactor with value display, improved disabled styling, and controlled/uncontrolled mode support |
| src/components/ui/slider/index.test.tsx | Added comprehensive test suite covering all component functionality |
| src/components/ui/slider/index.stories.tsx | Updated Storybook with new controlled and unit examples |
| src/components/ui/slider/index.figma.tsx | Added basic Figma Connect configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const [internalValue, setInternalValue] = React.useState<number[]>( | ||
| defaultValue || [0] |
There was a problem hiding this comment.
The fallback value [0] may not respect the component's min prop. If min is greater than 0, the initial state will be invalid. Consider using [min || 0] instead.
| const [internalValue, setInternalValue] = React.useState<number[]>( | |
| defaultValue || [0] | |
| defaultValue || [props.min ?? 0] |
- スライダーのデフォルト値を `defaultValue` または `props.min` に変更
| unit: "%", | ||
| }, | ||
| render: ({ className, ...props }) => ( | ||
| <div className="flex flex-col items-center justify-center w-[240px]"> |
There was a problem hiding this comment.
対応ありがとうございます!
桁が変わるタイミングでslider本体が縮んでしまっていました😭
https://github.com/user-attachments/assets/cb9d8988-a035-42e0-b0f2-8625b6dec3d6
There was a problem hiding this comment.
@ore0 今pushした状態で一応マルチバイト一文字+数字3文字ならスライダーの伸び縮みなくできそうな感じになりました!
これ思ったんですけどガタガタするので数字をmonospaceにできたらいいかなぁと思い始めたんですがどうでしょう?
There was a problem hiding this comment.
やっぱり桁が変わるタイミングで絶妙にタブがズレちゃって惜しいんですよね...
Figmaでも表現できないポイントなので、方針自体をすり合わせた方が良さそうです。
別の方法で値を表示することも検討した方がいいかもしれないです。
https://github.com/user-attachments/assets/a807cc81-5261-489c-8a50-7a14ba5adfab
There was a problem hiding this comment.
@ore0 これは自分が気づかなかった箇所なので最小幅を調整すれば防げるかなと思うのですがどうでしょう?
計算自体はvibe codingしたんでchなんてあるんだなーという気持ちで使ってたんですが以下見る感じ親要素の文字幅でやってるみたいなのでちょっとロジック調整するはやっても良さそうです
There was a problem hiding this comment.
あとそれでいうと挙動的にthumbの幅を想定できていないかも?です
There was a problem hiding this comment.
@ore0 今pushしたバージョンであれば自分の目視したところ解消できていると思うのですがいかがでしょう?
Thumbの設定値を元に調整しているので計算としても意味のあるものになっているかと思います(あと--spacingを使うことで設定が変わったシステムでも動きます)
- スライダーコンポーネントの表示幅を240pxから300pxに変更
- スライダーコンポーネントの幅を300pxから240pxに変更 - スライダーのレンダリングに関連するスタイルを調整
- スライダーコンポーネントの状態を更新し、テスト結果を反映しました。
- スライダーコンポーネントの関数形式を変更 - 不要なコードを削除し、可読性を向上 - スライダーの内部状態管理を整理 - JSX構造を簡素化し、データ属性を追加
- スライダーのルートスタイルを変更し、最小幅を設定 - スライダーのスパン要素の最小幅を変更し、フレックスシンクを適用
- 値インディケーターのクラス名を "min-w-10" から "min-w-14" に変更
- スライダーコンポーネントのテキストアラインメントを左揃えから右揃えに変更
- 値インディケーターの最小幅を桁数と単位に基づいて計算する機能を追加 - スライダーコンポーネントのスタイルを改善 - ヘルパー関数を追加して、最小幅の計算を行う
- 値インディケーターの最小幅を計算式を用いて設定 - スライダーのユニットに応じた最小幅の調整を実施


概要
指摘事項と調整です
https://www.notion.so/goodpatch-design-div/Slider-4e3de10abcde47d5977ba734eeac4335?source=copy_link
変更内容
動作確認
pnpm lintを実行pnpm build:packageを実行してパッケージが正常にビルドされることを確認pnpm testを実行してテストがすべて成功することを確認備考