Skip to content
API 风格:

Grid グリッド ​

24 カラムのグリッド制度です。CSS Grid で実装されており(grid-template-columns: repeat(24, 1fr))、span / offset は直接 grid-column にマッピングされるため、flex のパーセント換算は不要です。

基本的な使い方 ​

基本的な使い方
span 12
span 12
span 8
span 8
span 8
vue
<script setup lang="ts">
</script>

<template>
  <LhRow :gutter="12">
    <LhCol :span="12">span 12</LhCol>
    <LhCol :span="12">span 12</LhCol>
    <LhCol :span="8">span 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
  </LhRow>
</template>
vue
<script>
export default {}
</script>

<template>
  <LhRow :gutter="12">
    <LhCol :span="12">span 12</LhCol>
    <LhCol :span="12">span 12</LhCol>
    <LhCol :span="8">span 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
  </LhRow>
</template>

オフセットと整列 ​

オフセット / 整列
offset 3
中央
vue
<script setup lang="ts">
</script>

<template>
  <LhRow justify="center" align="middle" :gutter="12">
    <LhCol :span="6" :offset="3">offset 3</LhCol>
    <LhCol :span="6">中央</LhCol>
  </LhRow>
</template>
vue
<script>
export default {}
</script>

<template>
  <LhRow justify="center" align="middle" :gutter="12">
    <LhCol :span="6" :offset="3">offset 3</LhCol>
    <LhCol :span="6">中央</LhCol>
  </LhRow>
</template>

折り返し ​

wrap をオフにすると子要素は強制的に 1 行に並びます(overflow と組み合わせて横スクロールするグリッドを実現できます)。

折り返しなし
span 8
span 8
span 8
span 8
vue
<script setup lang="ts">
</script>

<template>
  <!-- 折り返しなし -->
  <LhRow :wrap="false" :gutter="12">
    <LhCol :span="8">span 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
  </LhRow>
</template>
vue
<script>
export default {}
</script>

<template>
  <!-- 折り返しなし -->
  <LhRow :wrap="false" :gutter="12">
    <LhCol :span="8">span 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
  </LhRow>
</template>

レスポンシブブレークポイント ​

xs / sm / md / lg / xl で段階的にサイズを宣言します(Tailwind のしきい値:640 / 768 / 1024 / 1280)。 未宣言の段階は下位にフォールバックし(xs が常に最終フォールバック)、いずれのブレークポイントも宣言しない場合は span が適用されます。ブラウザのウィンドウを縮小・拡大して変化を確認してください。

レスポンシブ
span 24 / md 12 / xl 8
span 24 / md 12 / xl 8
span 24 / xl 8
vue
<script setup lang="ts">
</script>

<template>
  <LhRow :gutter="12">
    <LhCol :span="24" :md="12" :xl="8">span 24 / md 12 / xl 8</LhCol>
    <LhCol :span="24" :md="12" :xl="8">span 24 / md 12 / xl 8</LhCol>
    <LhCol :span="24" :xl="8">span 24 / xl 8</LhCol>
  </LhRow>
</template>
vue
<script>
export default {}
</script>

<template>
  <LhRow :gutter="12">
    <LhCol :span="24" :md="12" :xl="8">span 24 / md 12 / xl 8</LhCol>
    <LhCol :span="24" :md="12" :xl="8">span 24 / md 12 / xl 8</LhCol>
    <LhCol :span="24" :xl="8">span 24 / xl 8</LhCol>
  </LhRow>
</template>

平移(push / pull) ​

push / pull は offset を踏まえて開始位置をずらします(右へ / 左へ)。列の位置を微調整するために使います。

push / pull
span 8 push 8
span 8
vue
<script setup lang="ts">
</script>

<template>
  <LhRow :gutter="12">
    <LhCol :span="8" :push="8">span 8 push 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
  </LhRow>
</template>
vue
<script>
export default {}
</script>

<template>
  <LhRow :gutter="12">
    <LhCol :span="8" :push="8">span 8 push 8</LhCol>
    <LhCol :span="8">span 8</LhCol>
  </LhRow>
</template>

後退とレスポンシブ ​

pull は列を左へ指定列数だけ後退させます(offset と逆方向)。xs / sm / md / lg / xl でブレークポイントごとに span を宣言し、sizes で一括宣言することもできます。

pull / レスポンシブブレークポイント
pull 2
レスポンシブ
sizes
vue
<script setup lang="ts">
</script>

<template>
  <LhRow :gutter="12">
    <LhCol :span="8" :pull="2">pull 2</LhCol>
    <LhCol :span="12" :xs="24" :sm="12" :lg="8">レスポンシブ</LhCol>
    <LhCol :span="10" :sizes="{ xs: 24, md: 12, xl: 6 }">sizes</LhCol>
  </LhRow>
</template>
vue
<script>
export default {}
</script>

<template>
  <LhRow :gutter="12">
    <LhCol :span="8" :pull="2">pull 2</LhCol>
    <LhCol :span="12" :xs="24" :sm="12" :lg="8">レスポンシブ</LhCol>
    <LhCol :span="10" :sizes="{ xs: 24, md: 12, xl: 6 }">sizes</LhCol>
  </LhRow>
</template>

API ​

LhRow Props ​

プロパティ説明型デフォルト値
justify主軸方向の配置'start' | 'center' | 'end' | 'space-between' | 'space-around''start'
align交差軸方向の整列'top' | 'middle' | 'bottom''top'
gutter列間の間隔(px または [水平, 垂直])number | [number, number]0
wrap折り返すかどうかbooleantrue
sxsx クイックレイアウトプロパティLhSxProps—

LhCol Props ​

プロパティ説明型デフォルト値
span占有する列数(24 カラム制)number—
offset左側のオフセット列数number—
push右へずらす列数number—
pull左へずらす列数number—
xs<640px で有効(未宣言時は下位にフォールバック)LhColSize—
sm≥640px で有効LhColSize—
md≥768px で有効LhColSize—
lg≥1024px で有効LhColSize—
xl≥1280px で有効LhColSize—
sizesブレークポイントごとに一括宣言(xs~xl と等価。どちらかを使用)Partial<Record<LhGridBreakpoint, LhColSize>>—
sxsx クイックレイアウトプロパティLhSxProps—

アクセシビリティ ​

  • 純粋なレイアウトコンポーネントであり、操作のセマンティクスは持ちません。セマンティックな構造が必要なリストの実装にグリッドを使用しないでください(List / Table などを使用してください)

型定義 ​

このコンポーネントが外部にエクスポートする TypeScript の型構造を以下に示します(packages/components/grid/src/types.ts および @lh-ui/share/core/* のソースから自動抽出。各エントリーをクリックすると完全な定義が表示されます。プロパティの説明は上の Props 表を参照してください):

LhRowJustify
ts
/** 子要素の主軸方向の配置 */
export type LhRowJustify = 'start' | 'center' | 'end' | 'space-between' | 'space-around'
LhRowAlign
ts
/** 子要素の交差軸方向の整列 */
export type LhRowAlign = 'top' | 'middle' | 'bottom'
LhRowProps
ts
export interface LhRowProps {
  /** 主軸方向の配置 */
  justify?: LhRowJustify
  /** 交差軸方向の整列 */
  align?: LhRowAlign
  /** 列間の間隔(px または [水平, 垂直]) */
  gutter?: number | [number, number]
  /** 折り返すかどうか */
  wrap?: boolean
  /** sx クイックレイアウトプロパティ */
  sx?: LhSxProps
}
LhColProps
ts
export interface LhColProps {
  /** 占有する列数(24 カラム制) */
  span?: number
  /** 左側のオフセット列数 */
  offset?: number
  /** 右へずらす列数 */
  push?: number
  /** 左へずらす列数 */
  pull?: number
  /** <640px で有効(未宣言時はより小さい段階にフォールバック) */
  xs?: LhColSize
  /** ≥640px で有効 */
  sm?: LhColSize
  /** ≥768px で有効 */
  md?: LhColSize
  /** ≥1024px で有効 */
  lg?: LhColSize
  /** ≥1280px で有効 */
  xl?: LhColSize
  /** ブレークポイントごとに一括宣言するレスポンシブサイズ(xs~xl と等価。どちらかを使用) */
  sizes?: LhBreakpointSizes
  /** sx クイックレイアウトプロパティ */
  sx?: LhSxProps
}
LhColSize (@lh-ui/share/core/grid より)
ts
/** Col のサイズ設定:数値またはオブジェクト(ブレークポイント別オブジェクトもサポート) */
export type LhColSize = number | LhGridSpan
LhGridSpan (@lh-ui/share/core/grid より)
ts
/** グリッドサイズ(1〜24 の span、または offset を伴うオブジェクト) */
export interface LhGridSpan {
  span?: number
  offset?: number
  push?: number
  pull?: number
}
LhBreakpointSizes (@lh-ui/share/core/grid より)
ts
/** ブレークポイント別に宣言するレスポンシブサイズ(未宣言の段階は下位にフォールバック。xs が常に最終フォールバック) */
export type LhBreakpointSizes = Partial<Record<LhGridBreakpoint, LhColSize>>
LhGridBreakpoint (@lh-ui/share/core/grid より)
ts
/** グリッドのブレークポイント */
export type LhGridBreakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl'

定数 ​

このコンポーネントで使用される公開定数は以下のとおりです(Props 表の「型 / デフォルト値」列から同名のエントリーをクリックするとここへジャンプします):

LH_GRID_COLUMNS (@lh-ui/share/core/grid より)
ts
/** グリッドの総列数 */
export const LH_GRID_COLUMNS = 24
LH_GRID_BREAKPOINTS (@lh-ui/share/core/grid より)
ts
/**
 * レスポンシブブレークポイント(Tailwind 風。幅の下限 px):
 * xs はデフォルト段階(<640)。それ以外は「≥ しきい値」で適用されます。
 */
export const LH_GRID_BREAKPOINTS: Record<LhGridBreakpoint, number> = {
  xs: 0,
  sm: 640,
  md: 768,
  lg: 1024,
  xl: 1280,
}
LH_GRID_BREAKPOINT_ORDER (@lh-ui/share/core/grid より)
ts
/** ブレークポイントの大から小への安定順序 */
export const LH_GRID_BREAKPOINT_ORDER: LhGridBreakpoint[] = ['xl', 'lg', 'md', 'sm', 'xs']

国風の美で、コードの基を築く