|
1 | 1 | /** |
2 | | - * Copyright IBM Corp. 2018, 2023 |
| 2 | + * Copyright IBM Corp. 2018, 2026 |
3 | 3 | * |
4 | 4 | * This source code is licensed under the Apache-2.0 license found in the |
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | */ |
7 | 7 |
|
8 | | -import { unstable_tokens } from './tokens.js'; |
| 8 | +import { unstable_tokens } from './tokens'; |
9 | 9 |
|
10 | 10 | export { unstable_tokens }; |
11 | 11 |
|
| 12 | +export type BreakpointName = 'sm' | 'md' | 'lg' | 'xlg' | 'max'; |
| 13 | +export type Breakpoint = { |
| 14 | + width: string; |
| 15 | + columns: number; |
| 16 | + margin: string; |
| 17 | +}; |
| 18 | +export type SizeName = |
| 19 | + | 'XSmall' |
| 20 | + | 'Small' |
| 21 | + | 'Medium' |
| 22 | + | 'Large' |
| 23 | + | 'XLarge' |
| 24 | + | '2XLarge'; |
| 25 | + |
12 | 26 | // Convert |
13 | 27 | // Default, Use with em() and rem() functions |
14 | 28 | export const baseFontSize = 16; |
15 | 29 |
|
16 | | -/** |
17 | | - * Convert a given px unit to a rem unit |
18 | | - * @param {number} px |
19 | | - * @returns {string} |
20 | | - */ |
21 | | -export function rem(px) { |
| 30 | +export const rem = (px: number) => { |
22 | 31 | return `${px / baseFontSize}rem`; |
23 | | -} |
| 32 | +}; |
24 | 33 |
|
25 | | -/** |
26 | | - * Convert a given px unit to a em unit |
27 | | - * @param {number} px |
28 | | - * @returns {string} |
29 | | - */ |
30 | | -export function em(px) { |
| 34 | +export const em = (px: number) => { |
31 | 35 | return `${px / baseFontSize}em`; |
32 | | -} |
| 36 | +}; |
33 | 37 |
|
34 | | -/** |
35 | | - * Convert a given px unit to its string representation |
36 | | - * @param {number} value - number of pixels |
37 | | - * @returns {string} |
38 | | - */ |
39 | | -export function px(value) { |
| 38 | +export const px = (value: number) => { |
40 | 39 | return `${value}px`; |
41 | | -} |
| 40 | +}; |
42 | 41 |
|
43 | 42 | // Breakpoint |
44 | 43 | // Initial map of our breakpoints and their values |
45 | | -export const breakpoints = { |
| 44 | +export const breakpoints: Record<BreakpointName, Breakpoint> = { |
46 | 45 | sm: { |
47 | 46 | width: rem(320), |
48 | 47 | columns: 4, |
@@ -70,24 +69,22 @@ export const breakpoints = { |
70 | 69 | }, |
71 | 70 | }; |
72 | 71 |
|
73 | | -export function breakpointUp(name) { |
| 72 | +export const breakpointUp = (name: BreakpointName) => { |
74 | 73 | return `@media (min-width: ${breakpoints[name].width})`; |
75 | | -} |
| 74 | +}; |
76 | 75 |
|
77 | | -export function breakpointDown(name) { |
| 76 | +export const breakpointDown = (name: BreakpointName) => { |
78 | 77 | return `@media (max-width: ${breakpoints[name].width})`; |
79 | | -} |
| 78 | +}; |
80 | 79 |
|
81 | | -export function breakpoint(...args) { |
82 | | - return breakpointUp(...args); |
83 | | -} |
| 80 | +export const breakpoint = breakpointUp; |
84 | 81 |
|
85 | 82 | // Mini-unit |
86 | 83 | export const miniUnit = 8; |
87 | 84 |
|
88 | | -export function miniUnits(count) { |
| 85 | +export const miniUnits = (count: number) => { |
89 | 86 | return rem(miniUnit * count); |
90 | | -} |
| 87 | +}; |
91 | 88 |
|
92 | 89 | // Spacing |
93 | 90 | export const spacing01 = miniUnits(0.25); |
@@ -169,7 +166,7 @@ export const sizeMedium = rem(40); |
169 | 166 | export const sizeLarge = rem(48); |
170 | 167 | export const sizeXLarge = rem(64); |
171 | 168 | export const size2XLarge = rem(80); |
172 | | -export const sizes = { |
| 169 | +export const sizes: Record<SizeName, string> = { |
173 | 170 | XSmall: sizeXSmall, |
174 | 171 | Small: sizeSmall, |
175 | 172 | Medium: sizeMedium, |
|
0 commit comments