@carbon/type 11.60.0 → 11.61.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.js +87 -99
- package/lib/__tests__/exports-test.d.ts +1 -0
- package/lib/__tests__/fluid-test.d.ts +1 -0
- package/lib/__tests__/fontFamily-test.d.ts +1 -0
- package/lib/__tests__/fontWeight-test.d.ts +1 -0
- package/lib/__tests__/reset-test.d.ts +1 -0
- package/lib/__tests__/scale-test.d.ts +1 -0
- package/lib/__tests__/styles-test.d.ts +1 -0
- package/lib/__tests__/tokens-test.d.ts +1 -0
- package/lib/fluid.d.ts +15 -0
- package/lib/fontFamily.d.ts +16 -0
- package/lib/fontWeight.d.ts +14 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.js +87 -99
- package/lib/print.d.ts +9 -0
- package/lib/reset.d.ts +8 -0
- package/lib/scale.d.ts +16 -0
- package/lib/styles.d.ts +744 -0
- package/lib/tokens.d.ts +65 -0
- package/lib/types.d.ts +16 -0
- package/package.json +8 -5
- package/umd/index.js +87 -99
- package/src/__tests__/__snapshots__/fontFamily-test.js.snap +0 -13
- package/src/__tests__/__snapshots__/fontWeight-test.js.snap +0 -11
- package/src/__tests__/__snapshots__/reset-test.js.snap +0 -11
- package/src/__tests__/__snapshots__/scale-test.js.snap +0 -29
- package/src/__tests__/__snapshots__/styles-test.js.snap +0 -411
- package/src/__tests__/exports-test.js +0 -88
- package/src/__tests__/fluid-test.js +0 -71
- package/src/__tests__/fontFamily-test.js +0 -33
- package/src/__tests__/fontWeight-test.js +0 -33
- package/src/__tests__/reset-test.js +0 -23
- package/src/__tests__/scale-test.js +0 -31
- package/src/__tests__/styles-test.js +0 -18
- package/src/__tests__/tokens-test.js +0 -21
- package/src/fluid.js +0 -86
- package/src/fontFamily.js +0 -30
- package/src/fontWeight.js +0 -24
- package/src/index.js +0 -28
- package/src/print.js +0 -36
- package/src/reset.js +0 -29
- package/src/scale.js +0 -30
- package/src/styles.js +0 -488
- package/src/tokens.js +0 -129
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2023
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @jest-environment node
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { unstable_tokens as tokens } from '../tokens';
|
|
11
|
-
import * as styles from '../styles';
|
|
12
|
-
|
|
13
|
-
describe('type tokens', () => {
|
|
14
|
-
test.each(tokens)('%s should be defined in styles', (token) => {
|
|
15
|
-
expect(styles[token]).toBeDefined();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test.each(Object.keys(styles))('%s should be defined in tokens', (token) => {
|
|
19
|
-
expect(tokens.indexOf(token)).not.toBe(-1);
|
|
20
|
-
});
|
|
21
|
-
});
|
package/src/fluid.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2023
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { breakpoint as bp, breakpoints } from '@carbon/layout';
|
|
9
|
-
|
|
10
|
-
const breakpointNames = Object.keys(breakpoints);
|
|
11
|
-
|
|
12
|
-
function next(name) {
|
|
13
|
-
return breakpointNames[breakpointNames.indexOf(name) + 1];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function fluid(selector) {
|
|
17
|
-
const { breakpoints: fluidBreakpoints, ...styles } = selector;
|
|
18
|
-
|
|
19
|
-
if (typeof fluidBreakpoints !== 'object') {
|
|
20
|
-
return styles;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const fluidBreakpointNames = Object.keys(fluidBreakpoints);
|
|
24
|
-
if (fluidBreakpointNames.length === 0) {
|
|
25
|
-
return styles;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
styles.fontSize = fluidTypeSize(styles, 'sm', fluidBreakpoints);
|
|
29
|
-
|
|
30
|
-
fluidBreakpointNames.forEach((name) => {
|
|
31
|
-
styles[bp(name)] = {
|
|
32
|
-
...fluidBreakpoints[name],
|
|
33
|
-
fontSize: fluidTypeSize(styles, name, fluidBreakpoints),
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return styles;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function fluidTypeSize(defaultStyles, fluidBreakpointName, fluidBreakpoints) {
|
|
41
|
-
const breakpoint = breakpoints[fluidBreakpointName];
|
|
42
|
-
const fluidBreakpoint =
|
|
43
|
-
fluidBreakpointName === 'sm'
|
|
44
|
-
? defaultStyles
|
|
45
|
-
: fluidBreakpoints[fluidBreakpointName];
|
|
46
|
-
|
|
47
|
-
let maxFontSize = defaultStyles.fontSize;
|
|
48
|
-
let minFontSize = defaultStyles.fontSize;
|
|
49
|
-
if (fluidBreakpoint.fontSize) {
|
|
50
|
-
minFontSize = fluidBreakpoint.fontSize;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let maxViewportWidth = breakpoint.width;
|
|
54
|
-
let minViewportWidth = breakpoint.width;
|
|
55
|
-
|
|
56
|
-
let nextBreakpointAvailable = next(fluidBreakpointName);
|
|
57
|
-
let nextFluidBreakpointName = null;
|
|
58
|
-
|
|
59
|
-
while (nextBreakpointAvailable) {
|
|
60
|
-
if (fluidBreakpoints[nextBreakpointAvailable]) {
|
|
61
|
-
nextFluidBreakpointName = nextBreakpointAvailable;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
nextBreakpointAvailable = next(nextBreakpointAvailable);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (nextFluidBreakpointName) {
|
|
68
|
-
const nextFluidBreakpoint = breakpoints[nextFluidBreakpointName];
|
|
69
|
-
maxFontSize = fluidBreakpoints[nextFluidBreakpointName].fontSize;
|
|
70
|
-
maxViewportWidth = nextFluidBreakpoint.width;
|
|
71
|
-
|
|
72
|
-
return `calc(${minFontSize} + ${subtract(
|
|
73
|
-
maxFontSize,
|
|
74
|
-
minFontSize
|
|
75
|
-
)} * ((100vw - ${minViewportWidth}) / ${subtract(
|
|
76
|
-
maxViewportWidth,
|
|
77
|
-
minViewportWidth
|
|
78
|
-
)}))`;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return minFontSize;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function subtract(a, b) {
|
|
85
|
-
return parseFloat(a) - parseFloat(b);
|
|
86
|
-
}
|
package/src/fontFamily.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2023
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// Font family fallbacks for: IBM Plex Mono, IBM Plex Sans, IBM Plex Sans
|
|
9
|
-
// Condensed, IBM Plex Sans Hebrew, and IBM Plex Serif
|
|
10
|
-
export const fontFamilies = {
|
|
11
|
-
mono: "'IBM Plex Mono', 'Menlo', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Courier, monospace",
|
|
12
|
-
sans: "'IBM Plex Sans', system-ui, -apple-system, BlinkMacSystemFont, '.SFNSText-Regular', sans-serif",
|
|
13
|
-
sansCondensed:
|
|
14
|
-
"'IBM Plex Sans Condensed', 'Helvetica Neue', Arial, sans-serif",
|
|
15
|
-
sansHebrew:
|
|
16
|
-
"'IBM Plex Sans Hebrew', 'Helvetica Hebrew', 'Arial Hebrew', sans-serif",
|
|
17
|
-
serif: "'IBM Plex Serif', 'Georgia', Times, serif",
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export function fontFamily(name) {
|
|
21
|
-
if (!fontFamilies[name]) {
|
|
22
|
-
throw new Error(
|
|
23
|
-
`Unable to find font family: \`${name}\`. Expected one of: ` +
|
|
24
|
-
`[${Object.keys(fontFamilies).join(', ')}]`
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
fontFamily: fontFamilies[name],
|
|
29
|
-
};
|
|
30
|
-
}
|
package/src/fontWeight.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2023
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export const fontWeights = {
|
|
9
|
-
light: 300,
|
|
10
|
-
regular: 400,
|
|
11
|
-
semibold: 600,
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export function fontWeight(weight) {
|
|
15
|
-
if (!fontWeights[weight]) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
`Unable to find font weight: \`${weight}\`. Expected one of: ` +
|
|
18
|
-
`[${Object.keys(fontWeights).join(', ')}]`
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
fontWeight: fontWeights[weight],
|
|
23
|
-
};
|
|
24
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2023
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { fontFamilies, fontFamily } from './fontFamily';
|
|
9
|
-
import { fontWeights, fontWeight } from './fontWeight';
|
|
10
|
-
import { print } from './print';
|
|
11
|
-
import { reset } from './reset';
|
|
12
|
-
import { getTypeSize, scale } from './scale';
|
|
13
|
-
import * as styles from './styles';
|
|
14
|
-
|
|
15
|
-
export { fluid } from './fluid';
|
|
16
|
-
export * from './styles';
|
|
17
|
-
export { unstable_tokens } from './tokens';
|
|
18
|
-
export {
|
|
19
|
-
fontFamilies,
|
|
20
|
-
fontFamily,
|
|
21
|
-
fontWeights,
|
|
22
|
-
fontWeight,
|
|
23
|
-
print,
|
|
24
|
-
reset,
|
|
25
|
-
getTypeSize,
|
|
26
|
-
scale,
|
|
27
|
-
styles,
|
|
28
|
-
};
|
package/src/print.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2023
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export function print(block) {
|
|
9
|
-
return Object.keys(block).reduce((acc, key, index) => {
|
|
10
|
-
// Short-circuit on the foreign key 'breakpoints'. This is used in our
|
|
11
|
-
// tokens for fluid type and should not be printed. In the future, we should
|
|
12
|
-
// tie this to media query outputs.
|
|
13
|
-
if (key === 'breakpoints') {
|
|
14
|
-
return acc;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const property = `${paramCase(key)}: ${block[key]};`;
|
|
18
|
-
if (index === 0) {
|
|
19
|
-
return property;
|
|
20
|
-
}
|
|
21
|
-
return acc + '\n' + property;
|
|
22
|
-
}, '');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function paramCase(string) {
|
|
26
|
-
let result = '';
|
|
27
|
-
for (let i = 0; i < string.length; i++) {
|
|
28
|
-
const character = string[i];
|
|
29
|
-
if (character === character.toUpperCase()) {
|
|
30
|
-
result += '-' + character.toLowerCase();
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
result += character;
|
|
34
|
-
}
|
|
35
|
-
return result;
|
|
36
|
-
}
|
package/src/reset.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2023
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { baseFontSize, px } from '@carbon/layout';
|
|
9
|
-
import { fontFamilies } from './fontFamily';
|
|
10
|
-
import { fontWeights } from './fontWeight';
|
|
11
|
-
|
|
12
|
-
export const reset = {
|
|
13
|
-
html: {
|
|
14
|
-
fontSize: px(baseFontSize),
|
|
15
|
-
},
|
|
16
|
-
body: {
|
|
17
|
-
fontFamily: fontFamilies.sans,
|
|
18
|
-
fontWeight: fontWeights.regular,
|
|
19
|
-
textRendering: 'optimizeLegibility',
|
|
20
|
-
'-webkit-font-smoothing': 'antialiased',
|
|
21
|
-
'-moz-osx-font-smoothing': 'grayscale',
|
|
22
|
-
},
|
|
23
|
-
strong: {
|
|
24
|
-
fontWeight: fontWeights.semibold,
|
|
25
|
-
},
|
|
26
|
-
code: {
|
|
27
|
-
fontFamily: fontFamilies.mono,
|
|
28
|
-
},
|
|
29
|
-
};
|
package/src/scale.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2018, 2023
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Get the type size for the given step
|
|
10
|
-
* @param {number} step
|
|
11
|
-
* @returns {number}
|
|
12
|
-
*/
|
|
13
|
-
export function getTypeSize(step) {
|
|
14
|
-
if (step <= 1) {
|
|
15
|
-
return 12;
|
|
16
|
-
}
|
|
17
|
-
// Yn = Yn-1 + {FLOOR[(n - 2) / 4] + 1} * 2
|
|
18
|
-
return getTypeSize(step - 1) + Math.floor((step - 2) / 4 + 1) * 2;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The default type scale for 23 steps. Inlined as an array here through running
|
|
23
|
-
* the follow step:
|
|
24
|
-
*
|
|
25
|
-
* > Array.from({ length: 23 }, (_, i) => getTypeSize(i + 1))
|
|
26
|
-
*/
|
|
27
|
-
export const scale = [
|
|
28
|
-
12, 14, 16, 18, 20, 24, 28, 32, 36, 42, 48, 54, 60, 68, 76, 84, 92, 102, 112,
|
|
29
|
-
122, 132, 144, 156,
|
|
30
|
-
];
|