
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@charcoal-ui/tailwind-config
Advanced tools
charcoal のカラーテーマやスペーシングなどの定数を元に tailwind.config.js を生成するライブラリです。
@charcoal-ui/tailwind-config
charcoal のカラーテーマやスペーシングなどの定数を元に tailwind.config.js を生成するライブラリです。
npm
npm i --save-dev @charcoal-ui/tailwind-config
yarn
yarn add -D @charcoal-ui/tailwind-config
Tailwind v4 の@config経由で引き続既存の設定を利用できます。
公式のマイグレーションガイドを参考した上以下の対応を行なってください。
- @import 'tailwindcss';
/* 現時点@layer 未対応 */
+ @import 'tailwindcss/theme.css';
+ @import 'tailwindcss/utilities.css';
+ @config '@charcoal-ui/tailwind-config' /** デフォルトのconfig使う場合 */
/* また */
+ @config '../tailwind.config.ts' /** v3 configへのpath */
tailwind.config.js の中で require
して使います。
const { config } = require('@charcoal-ui/tailwind-config')
/**
* @type {import('tailwindcss').Config}
*/
module.exports = {
darkMode: false,
content: ['./src/**/*.tsx', './src/**/*.html'],
presets: [config]
};
const { light, dark } = require('@charcoal-ui/theme')
const { createTailwindConfig } = require('@charcoal-ui/tailwind-config')
/**
* @type {import('tailwindcss').Config}
*/
module.exports = {
darkMode: false,
content: ['./src/**/*.tsx', './src/**/*.html'],
presets: [
createTailwindConfig({
version: 'v3',
theme: {
':root': light,
'@media (prefers-color-scheme: dark)': dark
}
})
]
};
createTailwindConfig
には以下のオプションを渡すことができます。
キー | 型 | 説明 |
---|---|---|
version | v1 v2 v3 | Tailwind.css のバージョン系統を指定します。色のキー名に使われる DEFAULT と default などの違いを内部で吸収します。 |
theme | Record<string, Theme> | 条件ごとの色の値のマッピングを渡します。:root は必須のキーです。以下詳細。 |
charcoal は Tailwind.css の通常のダークモード( dark:〇〇
系のクラス )をサポートしません。
なぜなら charcoal における「色」は、同じ名前でも light テーマと dark テーマで違うカラーコードであり得るからです。
これを表現するために @charcoal-ui/tailwind-config
では theme
というオプションを受け取ります。
createTailwindConfig({
version: 'v3',
theme: {
':root': light,
'@media (prefers-color-scheme: dark)': dark,
},
})
↑ は、:root
(つまり通常ケース)では light テーマを、システムの設定がダークモードである場合は dark テーマを使用することを表現します。:root
は必須のキーであり、ダークテーマ対応を行わないサービスであっても、必ず自身のプロダクトのカラーテーマを渡す必要があります。
theme
をこのように書くと、tailwind-config
は内部的に以下のような CSS Variables を生成します。
/* 以下はイメージです */
:root {
--tailwind-color-background1: #fff;
--tailwind-color-background2: #f5f5f5;
/* ... */
}
@media (prefers-color-scheme: dark) {
:root {
--tailwind-color-background1: #1f1f1f;
--tailwind-color-background2: #000000;
/* ... */
}
}
このとき、以下のように書く必要はありません。キーが @media
で始まる場合はビルド時に :root
が補われます。
{
theme: {
// これは間違い!!
'@media (prefers-color-scheme: dark)': {
':root': dark
},
// 正しくはこう
'@media (prefers-color-scheme: dark)': dark
}
}
theme のキーとして通常のセレクタを指定することもできます。これにより、ダークモードの切り替えが DOM の状態に依存するケースにも対応します。localStorage
など JS での切り替えを実装しているアプリケーションはこちらの方式(何かしら CSS セレクタで表現できる方法)を使ってください。
createTailwindConfig({
version: 'v3',
theme: {
':root': light,
'html[data-theme="dark"]': dark,
},
})
/* 以下はイメージです */
:root {
--tailwind-color-background1: #fff;
--tailwind-color-background2: #f5f5f5;
/* ... */
}
html[data-theme='dark'] {
--tailwind-color-background1: #1f1f1f;
--tailwind-color-background2: #000000;
/* ... */
}
Tailwind.css に通常存在するクラスについては公式ドキュメントを見てください。
@charcoal-ui/tailwind-config
が独自に定義しているクラスについては Storybook を見てください。
https://pixiv.github.io/charcoal/?path=/docs/tailwind-config-colors-doc--docs
FAQs
charcoal のカラーテーマやスペーシングなどの定数を元に tailwind.config.js を生成するライブラリです。
The npm package @charcoal-ui/tailwind-config receives a total of 2,612 weekly downloads. As such, @charcoal-ui/tailwind-config popularity was classified as popular.
We found that @charcoal-ui/tailwind-config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.