レイアウト

NextUIのプラグインは、さまざまなレイアウトのカスタマイズオプションを提供します。スペーシング単位、フォントサイズ、行の高さ、半径などを変更して、各テーマを好みに合わせてパーソナライズできます。

レイアウトトークンを使用すると、デフォルトのTailwind CSS構成をオーバーライドする必要なく、すべてのコンポーネントで均一な外観を確保できます。

module.exports = {
plugins: [
nextui({
layout: {}, // common layout options
themes: {
light: {
layout: {}, // light theme layout options
// ...
},
dark: {
layout: {}, // dark theme layout options
// ...
},
// ... custom themes
},
}),
],
};

レイアウトオプションは、すべてのコンポーネントに適用されます。

デフォルトレイアウト

レイアウトトークンのデフォルト値は次のとおりです。

module.exports = {
plugins: [
nextui({
layout: {
dividerWeight: "1px", // h-divider the default height applied to the divider component
disabledOpacity: 0.5, // this value is applied as opacity-[value] when the component is disabled
fontSize: {
tiny: "0.75rem", // text-tiny
small: "0.875rem", // text-small
medium: "1rem", // text-medium
large: "1.125rem", // text-large
},
lineHeight: {
tiny: "1rem", // text-tiny
small: "1.25rem", // text-small
medium: "1.5rem", // text-medium
large: "1.75rem", // text-large
},
radius: {
small: "8px", // rounded-small
medium: "12px", // rounded-medium
large: "14px", // rounded-large
},
borderWidth: {
small: "1px", // border-small
medium: "2px", // border-medium (default)
large: "3px", // border-large
},
},
themes: {
light: {
layout: {
hoverOpacity: 0.8, // this value is applied as opacity-[value] when the component is hovered
boxShadow: {
// shadow-small
small:
"0px 0px 5px 0px rgb(0 0 0 / 0.02), 0px 2px 10px 0px rgb(0 0 0 / 0.06), 0px 0px 1px 0px rgb(0 0 0 / 0.3)",
// shadow-medium
medium:
"0px 0px 15px 0px rgb(0 0 0 / 0.03), 0px 2px 30px 0px rgb(0 0 0 / 0.08), 0px 0px 1px 0px rgb(0 0 0 / 0.3)",
// shadow-large
large:
"0px 0px 30px 0px rgb(0 0 0 / 0.04), 0px 30px 60px 0px rgb(0 0 0 / 0.12), 0px 0px 1px 0px rgb(0 0 0 / 0.3)",
},
},
},
dark: {
layout: {
hoverOpacity: 0.9, // this value is applied as opacity-[value] when the component is hovered
boxShadow: {
// shadow-small
small:
"0px 0px 5px 0px rgb(0 0 0 / 0.05), 0px 2px 10px 0px rgb(0 0 0 / 0.2), inset 0px 0px 1px 0px rgb(255 255 255 / 0.15)",
// shadow-medium
medium:
"0px 0px 15px 0px rgb(0 0 0 / 0.06), 0px 2px 30px 0px rgb(0 0 0 / 0.22), inset 0px 0px 1px 0px rgb(255 255 255 / 0.15)",
// shadow-large
large:
"0px 0px 30px 0px rgb(0 0 0 / 0.07), 0px 30px 60px 0px rgb(0 0 0 / 0.26), inset 0px 0px 1px 0px rgb(255 255 255 / 0.15)",
},
},
},
},
}),
],
};

CSS変数

NextUIは、各レイアウトトークンに対して--prefix-prop-name-scale形式を使用してCSS変数を作成します。デフォルトでは、プレフィックスはnextuiですが、prefixオプションで変更できます。

module.exports = {
plugins: [
nextui({
prefix: "myapp",
}),
],
};

次に、CSSファイルでCSS変数を使用できます。

/* With default prefix */
.my-button {
font-size: var(--nextui-font-size-small);
line-height: var(--nextui-line-height-small);
border-radius: var(--nextui-radius-medium);
}
/* With custom prefix */
.my-component {
font-size: var(--myapp-font-size-small);
line-height: var(--myapp-line-height-small);
border-radius: var(--myapp-radius-medium);
}

APIリファレンス

属性タイプ説明
hoverOpacitystring, numberコンポーネントがホバーされたときにopacity-[値]として適用される0から1の間の数値。
disabledOpacitystring, numberコンポーネントが無効になっているときにopacity-[値]として適用される0から1の間の数値。
dividerWeightstringdividerコンポーネントに適用されるデフォルトの高さ。px単位を使用することをお勧めします。
fontSizeFontThemeUnitコンポーネント全体に適用されるデフォルトのフォントサイズ。
lineHeightFontThemeUnitコンポーネント全体に適用されるデフォルトの行の高さ。
radiusBaseThemeUnitコンポーネント全体に適用されるデフォルトの半径。rem単位を使用することをお勧めします。
borderWidthBaseThemeUnitコンポーネント全体に適用されるボーダー幅。
boxShadowBaseThemeUnitコンポーネント全体に適用されるボックスシャドウ。

BaseThemeUnit

export type BaseThemeUnit = {
small?: string;
medium?: string;
large?: string;
};

FontThemeUnit

export type FontThemeUnit = {
small?: string;
medium?: string;
large?: string;
tiny?: string;
};