Skip to content

Conversation

@piyoppi
Copy link
Contributor

@piyoppi piyoppi commented Oct 28, 2025

Buttonのmodifier的なスタイルを選択的にmixinできるようにします。これにより、必要なスタイルだけをビルド結果で得られるようにし、バンドルサイズを最適化できるようにします。

style-with-variants というmixinを新たに定義し、以下のように役割を分けます。

  • style mixin: これまでどおりの機能を提供する (すべてのバリエーションのスタイルを提供)
  • style-with-variants mixin: デフォルトスタイルと必要な属性に対するスタイルを提供する

このようなパッチを入れると、Storybook上で選択的にスタイルをmixinできることを確認できます。この場合は、設定したappearanceとcolorとsize以外のすべての属性が無効(スタイルが適用されない)になります。

diff --git a/packages/stories-web/index.scss b/packages/stories-web/index.scss
index c9657c7..7f2f0ec 100644
--- a/packages/stories-web/index.scss
+++ b/packages/stories-web/index.scss
@@ -1,2 +1,12 @@
 @use "@pepabo-inhouse/flavor" as flavor;
+@use "@pepabo-inhouse/button";
+
 @include flavor.icon-font;
+
+.in-button-partial {
+  @include button.style-with-variants($variants: (
+    appearance: (flat, solid),
+    color: (interactive, neutral),
+    size: (m, l)
+  ));
+}
diff --git a/packages/stories-web/src/components/button/Button.tsx b/packages/stories-web/src/components/button/Button.tsx
index 95dda04..eaf8f50 100644
--- a/packages/stories-web/src/components/button/Button.tsx
+++ b/packages/stories-web/src/components/button/Button.tsx
@@ -33,7 +33,7 @@ const Button: FC<Props> = (props: Props) => {
     ...rest
   } = props

-  const classes = ['in-button']
+  const classes = ['in-button-partial']

   if (typeof appearance !== 'undefined') {
     classes.push(`-appearance-${appearance}`)

@piyoppi piyoppi force-pushed the partial-button-styles branch 6 times, most recently from b859f61 to 3ba2898 Compare October 28, 2025 10:47
@piyoppi piyoppi changed the title Buttonの属性を選択できるようにして必要なスタイルのみをmixinできるようにする Buttonで利用する属性を選択できるようにして必要なスタイルのみをmixinできるようにする Oct 28, 2025
必要なスタイルのみを選択的に利用できるようにすることでビルドサイズを最適化できるようにする
@piyoppi piyoppi force-pushed the partial-button-styles branch from 3ba2898 to d6017a6 Compare October 28, 2025 10:54
@piyoppi piyoppi marked this pull request as ready for review October 29, 2025 01:36
@piyoppi piyoppi requested a review from a team as a code owner October 29, 2025 01:36
Copy link
Collaborator

@fumink7 fumink7 left a comment

Choose a reason for hiding this comment

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

すごい、よさそうに思いました!✨

一つコメントしてます!!

/// color: (primary, neutral),
/// size: (m, l)
/// ));
@mixin style-with-variants($default-style: variables.$default-option, $variants: ()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

$default-styleを省略すること多そうなので、第一引数が$variantsのほうが良かったりします?
(名前付きで引数渡すなら関係ないですが…)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

そのほうがよさそうです。de1b6c5 で対応しました 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

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

ありがとうございます!

@piyoppi piyoppi requested a review from fumink7 October 30, 2025 09:53
@nio-nio-nio nio-nio-nio self-requested a review November 4, 2025 06:05
Copy link
Contributor

@nio-nio-nio nio-nio-nio left a comment

Choose a reason for hiding this comment

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

storybookで動作確認を行い、通常通りの挙動を確認したためApproveしました!🙏
実装内容も良さそうでした!

@piyoppi piyoppi merged commit 8443896 into main Nov 4, 2025
2 checks passed
@piyoppi piyoppi deleted the partial-button-styles branch November 4, 2025 06:16
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.

4 participants