Skip to content

Commit

Permalink
add columns
Browse files Browse the repository at this point in the history
  • Loading branch information
fibo committed May 17, 2024
1 parent c909606 commit 1ae7bc5
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 152 deletions.
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"devDependencies": {
"@types/node": "^20.12.12",
"@types/react": "^18.3.2",
"postcss": "^8",
"postcss-cli": "^10",
"postcss-ts-classnames": "^0.3.0",
Expand Down
61 changes: 61 additions & 0 deletions packages/bulma/src/columns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { classnames } from "@trunx/classnames"
import { BoolClassArg, boolClass } from "./bool.js"
import { Dozen, Fraction, Gap } from "./numbers.js"
import { BreakpointsMap } from "./responsiveness.js"

export type ColumnClassArg = Pick<BoolClassArg, "isCentered"> &
Partial<{
isNarrow: boolean | BreakpointsMap<boolean>
offset: Exclude<Dozen, 12> | Fraction
size: Dozen | Fraction | BreakpointsMap<Dozen | Fraction>
}>

export const columnClass = ({
isCentered,
isNarrow,
offset,
size,
}: ColumnClassArg) =>
classnames(
"column",
boolClass({ isCentered }),
isNarrow === true
? {
"is-narrow": isNarrow,
}
: isNarrow && typeof isNarrow === "object"
? Object.entries(isNarrow).map(([breakpoint, enabled]) =>
enabled ? `is-narrow-${breakpoint}` : ""
)
: "",
offset ? `is-offset-${offset}` : "",
size
? size && typeof size === "object"
? Object.entries(size).map(
([breakpoint, value]) => `is-${value}-${breakpoint}`
)
: `is-${size}`
: ""
)

export type ColumnsClassArg = Pick<
BoolClassArg,
| "isCentered"
| "isDesktop"
| "isGapless"
| "isMobile"
| "isNarrow"
| "isMultiline"
| "isVariable"
| "isVcentered"
> &
Partial<{
gap: Gap | BreakpointsMap<Gap>
}>

export const columnsClass = ({ gap, ...bools }: ColumnsClassArg) =>
classnames(
"columns",
boolClass(bools),
typeof gap === "number" ? `is-${gap}` : undefined
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from "node:assert/strict"
import { test } from "node:test"
import { BulmaClass } from "@trunx/bulma"
import { columnClass, ColumnClassArg } from "./Column.js"
import BulmaClass from "./BulmaClass.js"
import { columnClass, ColumnClassArg } from "./columns.js"

test("columnClass", () => {
const testData: Array<{
Expand Down
13 changes: 8 additions & 5 deletions packages/bulma/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
export * from "./bulma.js"

export * from "./bool.js"
export * from "./buttons.js"
export * from "./color.js"
export * from "./image.js"
export * from "./layout.js"
export * from "./miscellanea.js"
export * from "./number.js"
export * from "./numbers.js"
export * from "./responsiveness.js"
export * from "./size.js"
export * from "./typography.js"
export * from "./bulma.js"

export * from "./buttons.js"
export * from "./columns.js"
export * from "./image.js"
export * from "./miscellanea.js"
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type Gap = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8

export type HalfDozen = 1 | 2 | 3 | 4 | 5 | 6

export type Dozen = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
Expand Down
21 changes: 21 additions & 0 deletions packages/react/src/columns.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FC, PropsWithChildren } from "react"
import {
ColumnClassArg,
ColumnsClassArg,
columnClass,
columnsClass,
} from "@trunx/bulma"

export type ColumnProps = ColumnClassArg

export const Column: FC<PropsWithChildren<ColumnProps>> = ({
children,
...props
}) => <div className={columnClass(props)}>{children}</div>

export type ColumnsProps = ColumnsClassArg

export const Columns: FC<PropsWithChildren<ColumnsProps>> = ({
children,
...props
}) => <div className={columnsClass(props)}>{children}</div>
1 change: 1 addition & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./buttons.js"
export * from "./columns.js"
export * from "./miscellanea.js"
105 changes: 0 additions & 105 deletions packages/trunx/src/components/Column.tsx

This file was deleted.

40 changes: 0 additions & 40 deletions packages/trunx/src/components/Columns.tsx

This file was deleted.

0 comments on commit 1ae7bc5

Please sign in to comment.