@charcoal-ui/styled 1.0.0-alpha.1 → 1.0.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/dist/util.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Function used to assert a given code path is unreachable
3
+ */
4
+ export declare function unreachable(): never;
5
+ /**
6
+ * Function used to assert a given code path is unreachable.
7
+ * Very useful for ensuring switches are exhaustive:
8
+ *
9
+ * ```ts
10
+ * switch (a.type) {
11
+ * case Types.A:
12
+ * case Types.B:
13
+ * break
14
+ * default:
15
+ * unreachable(a) // will cause a build error if there was
16
+ * // a Types.C that was not checked
17
+ * }
18
+ * ```
19
+ *
20
+ * @param value Value to be asserted as unreachable
21
+ */
22
+ export declare function unreachable(value: never): never;
23
+ /**
24
+ * Check whether a value is non-null and non-undefined
25
+ *
26
+ * @param value nullable
27
+ */
28
+ export declare const isPresent: <T>(value: T) => value is NonNullable<T>;
29
+ declare type Head<U> = U extends [infer T, ...any[]] ? T : never;
30
+ declare type Tail<U> = U extends [any, any, ...any[]] ? ((...args: U) => any) extends (head: any, ...args: infer T) => any ? T : never : never;
31
+ declare type RecursiveObjectAssign<T, S extends any[]> = {
32
+ 0: T & Head<S>;
33
+ 1: RecursiveObjectAssign<T & Head<S>, Tail<S>>;
34
+ }[Tail<S> extends never ? 0 : 1];
35
+ declare type ObjectAssign<T extends any[]> = RecursiveObjectAssign<Record<string, unknown>, T>;
36
+ export declare function objectAssign<T extends any[]>(...sources: T): ObjectAssign<T>;
37
+ export declare function objectKeys<V, K extends keyof V>(obj: V): K[];
38
+ export interface ReadonlyArrayConstructor {
39
+ isArray(value: any): value is readonly any[];
40
+ }
41
+ export declare function extractNonNullKeys<V, K extends keyof V>(obj: {
42
+ [key in K]: V[key];
43
+ }): { [key in K]: V[key] extends null ? never : key; }[K][];
44
+ export {};
45
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.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AC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,OAEtD;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,SAAS,GAAG,EAAE,CAAA;CAC7C;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE;KAC3D,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;CACnB,2DAIA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charcoal-ui/styled",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -13,11 +13,9 @@
13
13
  "types": "./dist/index.d.ts",
14
14
  "sideEffects": false,
15
15
  "scripts": {
16
- "build": "microbundle -f modern,esm,cjs --tsconfig tsconfig.build.json && yarn serialize",
17
- "typecheck": "tsc --noEmit --project tsconfig.build.json && yarn typecheck:cli",
18
- "typecheck:cli": "tsc --noEmit --project cli/tsconfig.build.json",
19
- "clean": "rimraf dist",
20
- "serialize": "node cli/index.js"
16
+ "build": "microbundle -f modern,esm,cjs --tsconfig tsconfig.build.json",
17
+ "typecheck": "tsc --noEmit --project tsconfig.build.json",
18
+ "clean": "rimraf dist"
21
19
  },
22
20
  "devDependencies": {
23
21
  "@types/react": "^17.0.38",
@@ -25,17 +23,15 @@
25
23
  "@types/warning": "^3.0.0",
26
24
  "microbundle": "^0.14.2",
27
25
  "npm-run-all": "^4.1.5",
28
- "polished": "^4.1.4",
29
26
  "react": "^17.0.2",
30
27
  "rimraf": "^3.0.2",
31
28
  "styled-components": "^5.3.3",
32
29
  "typescript": "^4.5.5"
33
30
  },
34
31
  "dependencies": {
35
- "@charcoal-ui/foundation": "^1.0.0-alpha.1",
36
- "@charcoal-ui/pixiv-theme": "^1.0.0-alpha.1",
37
- "@charcoal-ui/theme": "^1.0.0-alpha.1",
38
- "@charcoal-ui/utils": "^1.0.0-alpha.1",
32
+ "@charcoal-ui/foundation": "^1.0.0",
33
+ "@charcoal-ui/theme": "^1.0.0",
34
+ "@charcoal-ui/utils": "^1.0.0",
39
35
  "warning": "^4.0.3"
40
36
  },
41
37
  "peerDependencies": {
@@ -44,11 +40,10 @@
44
40
  },
45
41
  "files": [
46
42
  "src",
47
- "dist",
48
- "theme.json"
43
+ "dist"
49
44
  ],
50
45
  "publishConfig": {
51
46
  "access": "public"
52
47
  },
53
- "gitHead": "1d09e09a796f92782be600672efb5c80a6a7b51b"
48
+ "gitHead": "addc6d8f443865a8b56327ef9a4ff2e69942a30b"
54
49
  }
@@ -1,8 +1,8 @@
1
1
  import React from 'react'
2
2
  import styled, { CSSProp, DefaultTheme, ThemeProvider } from 'styled-components'
3
- import { ElementsTheme } from './theme'
3
+ import { CharcoalTheme } from '@charcoal-ui/theme'
4
+ import { Material } from '@charcoal-ui/foundation'
4
5
  import createTheme, { ThemeProp } from '.'
5
- import { GradientMaterial } from '@charcoal-ui/theme'
6
6
  import { disabledSelector } from '@charcoal-ui/utils'
7
7
 
8
8
  export default {
@@ -15,21 +15,18 @@ declare module 'react' {
15
15
  }
16
16
  }
17
17
 
18
- type MyTheme = ElementsTheme & {
19
- gradientColor: {
20
- callToAction: GradientMaterial
18
+ type MyTheme = CharcoalTheme & {
19
+ color: {
20
+ mycolor: Material
21
21
  }
22
22
  }
23
23
 
24
- function myTheme(theme: ElementsTheme): MyTheme {
24
+ function myTheme(theme: CharcoalTheme): MyTheme {
25
25
  return {
26
26
  ...theme,
27
- gradientColor: {
28
- callToAction: [
29
- { color: '#d1ff1a', ratio: 0 },
30
- { color: '#1ad1ff', ratio: 100 },
31
- ],
32
- ...theme.gradientColor,
27
+ color: {
28
+ ...theme.color,
29
+ mycolor: '#ff9e8c',
33
30
  },
34
31
  }
35
32
  }
@@ -95,7 +92,7 @@ export const TailwindLike = () => (
95
92
  >
96
93
  <div
97
94
  css={theme((o) => [
98
- o.bg.premium.hover.press,
95
+ o.bg.mycolor.hover.press,
99
96
  o.font.text5.hover.press,
100
97
  o.typography(14).bold,
101
98
  o.padding.all(16),
package/src/index.ts CHANGED
@@ -6,7 +6,11 @@ import {
6
6
  constFactory,
7
7
  modifiedArgumentedFactory,
8
8
  } from './lib'
9
- import { EffectType, StyledTheme as Theme, Key } from './types'
9
+ import {
10
+ EffectType,
11
+ CharcoalAbstractTheme as Theme,
12
+ Key,
13
+ } from '@charcoal-ui/theme'
10
14
  import {
11
15
  objectAssign,
12
16
  unreachable,
@@ -14,8 +18,9 @@ import {
14
18
  objectKeys,
15
19
  isPresent,
16
20
  } from './util'
17
- import { columnPx, halfLeading } from '@charcoal-ui/foundation'
21
+ import { columnSystem } from '@charcoal-ui/foundation'
18
22
  import {
23
+ halfLeading,
19
24
  applyEffect,
20
25
  applyEffectToGradient,
21
26
  dur,
@@ -27,9 +32,6 @@ import {
27
32
  } from '@charcoal-ui/utils'
28
33
  export { type Modified, type ModifiedArgumented } from './lib'
29
34
 
30
- import { light, dark } from './theme'
31
- export { type ElementsTheme } from './theme'
32
-
33
35
  const colorProperties = ['bg', 'font'] as const
34
36
  type ColorProperty = typeof colorProperties[number]
35
37
 
@@ -542,10 +544,12 @@ const createFixedRelativeCss =
542
544
  }))
543
545
 
544
546
  const createFixedColumnCss =
545
- <T extends Theme>(_theme: T) =>
547
+ <T extends Theme>(theme: T) =>
546
548
  (property: FixedProperty, span: number): Internal =>
547
549
  internal(() => ({
548
- [property]: px(columnPx(span)),
550
+ [property]: px(
551
+ columnSystem(span, theme.grid.unit.column, theme.grid.unit.gutter)
552
+ ),
549
553
  }))
550
554
 
551
555
  const createElementEffectCss =
@@ -712,9 +716,6 @@ function createTheme<T extends Theme>(_styled?: ThemedStyledInterface<T>) {
712
716
  }
713
717
  }
714
718
 
715
- // default export を疑似esmにしないようにする hack
716
- createTheme.light = light
717
- createTheme.dark = dark
718
719
  export default createTheme
719
720
 
720
721
  export type ThemeProp<T> = ({ theme }: { theme: T }) => CSSObject | CSSObject[]
package/src/lib.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Key } from './types'
1
+ import { Key } from '@charcoal-ui/theme'
2
2
  import { unreachable } from './util'
3
3
 
4
4
  /**
package/src/theme.ts DELETED
@@ -1,107 +0,0 @@
1
- import { StyledTheme } from './types'
2
- import {
3
- BorderRadius,
4
- Spacing,
5
- Typography,
6
- borderRadius,
7
- spacing,
8
- typography,
9
- Breakpoint,
10
- breakpoint,
11
- } from '@charcoal-ui/foundation'
12
- import { light as l, dark as d } from '@charcoal-ui/pixiv-theme'
13
- import { Effect, Material, OpacityEffect, Theme } from '@charcoal-ui/theme'
14
- import { applyEffect } from '@charcoal-ui/utils'
15
-
16
- export interface ElementsTheme extends StyledTheme {
17
- color: Theme['color']
18
- gradientColor: Theme['gradientColor']
19
- effect: {
20
- hover: Effect
21
- press: Effect
22
- }
23
- elementEffect: {
24
- disabled: OpacityEffect
25
- }
26
- spacing: Spacing
27
- typography: {
28
- size: Typography
29
- }
30
- borderRadius: BorderRadius
31
- border: {
32
- default: {
33
- color: Material
34
- }
35
- }
36
- outline: {
37
- default: {
38
- color: string
39
- weight: 4
40
- }
41
- assertive: {
42
- color: string
43
- weight: 4
44
- }
45
- }
46
- breakpoint: Breakpoint
47
- }
48
-
49
- const outlineEffect = {
50
- type: 'opacity',
51
- opacity: 0.32,
52
- } as const
53
-
54
- const common = {
55
- borderRadius,
56
- spacing,
57
- typography: {
58
- size: typography,
59
- },
60
- breakpoint,
61
- }
62
-
63
- export const light: ElementsTheme = {
64
- color: l.color,
65
- gradientColor: l.gradientColor,
66
- effect: l.effect,
67
- elementEffect: l.elementEffect,
68
- border: {
69
- default: {
70
- color: l.color.border,
71
- },
72
- },
73
- outline: {
74
- default: {
75
- color: applyEffect(l.color.brand, outlineEffect),
76
- weight: 4,
77
- },
78
- assertive: {
79
- color: applyEffect(l.color.assertive, outlineEffect),
80
- weight: 4,
81
- },
82
- },
83
- ...common,
84
- }
85
-
86
- export const dark: ElementsTheme = {
87
- color: d.color,
88
- gradientColor: d.gradientColor,
89
- effect: d.effect,
90
- elementEffect: d.elementEffect,
91
- border: {
92
- default: {
93
- color: d.color.border,
94
- },
95
- },
96
- outline: {
97
- default: {
98
- color: applyEffect(d.color.brand, outlineEffect),
99
- weight: 4,
100
- },
101
- assertive: {
102
- color: applyEffect(d.color.assertive, outlineEffect),
103
- weight: 4,
104
- },
105
- },
106
- ...common,
107
- }
package/src/types.ts DELETED
@@ -1,43 +0,0 @@
1
- import { TypographyDescriptor } from '@charcoal-ui/foundation'
2
- import {
3
- Effect,
4
- GradientMaterial,
5
- Material,
6
- OpacityEffect,
7
- } from '@charcoal-ui/theme'
8
-
9
- export type EffectType = 'hover' | 'press' | 'disabled'
10
-
11
- export type Key = string | number | symbol
12
-
13
- export type ColorStyleTheme = {
14
- [key in Key]: Material
15
- }
16
-
17
- export interface StyledTheme {
18
- color: ColorStyleTheme
19
- gradientColor: { [key in Key]: GradientMaterial }
20
- effect: { [key in EffectType]?: Effect }
21
- elementEffect: { [key in EffectType]?: OpacityEffect }
22
- spacing: { [key in Key]: number }
23
- typography: {
24
- size: { [key in Key]: TypographyDescriptor }
25
- // TODO
26
- // weight: { [key in Key]: string }
27
- // variant: { [key in Key]: string }
28
- }
29
- borderRadius: { [key in Key]: number }
30
- border: {
31
- [key in Key]: {
32
- color: Material
33
- // TODO
34
- // thickness: number
35
- }
36
- }
37
- outline: {
38
- [key in Key]: {
39
- color: Material
40
- weight: number
41
- }
42
- }
43
- }