Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TailwindCSSで学ぶ技術批判の気をつけ方

imaimai17468
September 05, 2024
6k

 TailwindCSSで学ぶ技術批判の気をつけ方

imaimai17468

September 05, 2024
Tweet

Transcript

  1. classNameの設計・分割 classNameの分割・結合にはtailwind-marge + clsxがおすすめ import { merge } from 'tailwind-merge';

    import clsx from 'clsx'; const checkboxClass = merge( 'h-4 w-4', clsx({ 'bg-blue-500 border-blue-500': isChecked, 'bg-gray-500 border-gray-500': !isChecked, }) ); <input type="checkbox" className={checkboxClass} checked={isChecked} /> 12
  2. variantsによって切り替えたいものはTailwind Variantsがおすすめ import { tv } from 'tailwind-variants'; const button

    = tv({ base: 'px-4 py-2 font-semibold', variants: { color: { primary: 'bg-blue-500 text-white', secondary: 'bg-gray-500 text-black', }, }, }); <button className={button({ color: 'primary' })}>Primary Button</button> 13