@charcoal-ui/styled 2.8.0 → 2.9.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.
@@ -4,7 +4,7 @@ export interface ThemeMap<T extends Theme> {
4
4
  [mediaQuery: `@media (${string})`]: T;
5
5
  [selector: string]: T;
6
6
  }
7
- type Theme = Pick<CharcoalAbstractTheme, 'color' | 'effect'>;
7
+ type Theme = Pick<CharcoalAbstractTheme, 'color' | 'effect' | 'border'>;
8
8
  export default function TokenInjector<T extends Theme>({ theme: themeMap, background, }: {
9
9
  theme: ThemeMap<T>;
10
10
  background?: keyof ThemeMap<T>[string]['color'];
@@ -1 +1 @@
1
- {"version":3,"file":"TokenInjector.d.ts","sourceRoot":"","sources":["../src/TokenInjector.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAqC1D,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,KAAK;IACvC,OAAO,EAAE,CAAC,CAAA;IACV,CAAC,UAAU,EAAE,WAAW,MAAM,GAAG,GAAG,CAAC,CAAA;IACrC,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAA;CACtB;AAED,KAAK,KAAK,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAA;AAE5D,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,CAAC,SAAS,KAAK,EAAE,EACrD,KAAK,EAAE,QAAQ,EACf,UAAU,GACX,EAAE;IACD,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAA;CAChD,eAEA"}
1
+ {"version":3,"file":"TokenInjector.d.ts","sourceRoot":"","sources":["../src/TokenInjector.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAsC1D,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,KAAK;IACvC,OAAO,EAAE,CAAC,CAAA;IACV,CAAC,UAAU,EAAE,WAAW,MAAM,GAAG,GAAG,CAAC,CAAA;IACrC,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAA;CACtB;AAED,KAAK,KAAK,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAA;AAEvE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,CAAC,SAAS,KAAK,EAAE,EACrD,KAAK,EAAE,QAAQ,EACf,UAAU,GACX,EAAE;IACD,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAA;CAChD,eAEA"}
@@ -2,7 +2,7 @@ import { CharcoalAbstractTheme } from '@charcoal-ui/theme';
2
2
  import { Internal } from '../internals';
3
3
  export declare const borderDirections: readonly ["top", "right", "bottom", "left"];
4
4
  type BorderDirection = (typeof borderDirections)[number];
5
- export declare const createBorderCss: <T extends CharcoalAbstractTheme>(theme: T) => (variant: keyof T["border"], directions: readonly BorderDirection[]) => Internal;
5
+ export declare const createBorderCss: <T extends CharcoalAbstractTheme>(variant: keyof T["border"], directions: readonly BorderDirection[]) => Internal;
6
6
  export default function border<T extends CharcoalAbstractTheme>(theme: T): Readonly<{
7
7
  border: { readonly [key in keyof T["border"] & string]: import("../factories/lib").PropertyChain<Internal, "bottom" | "left" | "right" | "top">; };
8
8
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"border.d.ts","sourceRoot":"","sources":["../../src/builders/border.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAG1D,OAAO,EAAE,QAAQ,EAAkB,MAAM,cAAc,CAAA;AAOvD,eAAO,MAAM,gBAAgB,6CAA8C,CAAA;AAC3E,KAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAA;AAUxD,eAAO,MAAM,eAAe,0FAIZ,SAAS,eAAe,EAAE,KACrC,QAmBF,CAAA;AAEH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,SAAS,qBAAqB,EAAE,KAAK,EAAE,CAAC;;GAevE"}
1
+ {"version":3,"file":"border.d.ts","sourceRoot":"","sources":["../../src/builders/border.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAG1D,OAAO,EAAE,QAAQ,EAAkB,MAAM,cAAc,CAAA;AAQvD,eAAO,MAAM,gBAAgB,6CAA8C,CAAA;AAC3E,KAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAA;AAExD,eAAO,MAAM,eAAe,4EAEd,SAAS,eAAe,EAAE,KACrC,QAsBF,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,SAAS,qBAAqB,EAAE,KAAK,EAAE,CAAC;;GAcvE"}
package/dist/index.cjs.js CHANGED
@@ -88,6 +88,9 @@ var variable = (value) => `var(${value})`;
88
88
  function onEffectPseudo(effect, css2) {
89
89
  return effect === "hover" ? { "&:hover": { [import_utils.notDisabledSelector]: css2 } } : effect === "press" ? { "&:active": { [import_utils.notDisabledSelector]: css2 } } : effect === "disabled" ? { [import_utils.disabledSelector]: css2 } : unreachable(effect);
90
90
  }
91
+ function withPrefixes(...parts) {
92
+ return parts.join("-");
93
+ }
91
94
 
92
95
  // src/internals/index.ts
93
96
  var internalSym = Symbol("internal");
@@ -169,23 +172,20 @@ var defineMethodChains = (modifiers, source, ..._inferPhantom) => function defin
169
172
  }([]);
170
173
 
171
174
  // src/builders/border.ts
175
+ var import_utils2 = require("@charcoal-ui/utils");
172
176
  var borderDirections = ["top", "right", "bottom", "left"];
173
- function borderProperty(direction) {
174
- return `border-${direction}`;
175
- }
176
- function borderShorthand(color) {
177
- return `solid 1px ${color}`;
178
- }
179
- var createBorderCss = (theme) => (variant, directions) => {
177
+ var createBorderCss = (variant, directions) => {
180
178
  const all = directions.length === 0;
181
- const value = borderShorthand(theme.border[variant].color);
179
+ const value = `solid 1px ${variable(
180
+ (0, import_utils2.customPropertyToken)(withPrefixes("border", variant.toString()))
181
+ )}`;
182
182
  return createInternal({
183
183
  toCSS() {
184
184
  return {
185
185
  ...all ? { border: value } : directions.reduce(
186
186
  (acc, direction) => ({
187
187
  ...acc,
188
- [borderProperty(direction)]: value
188
+ [`border-${direction}`]: value
189
189
  }),
190
190
  {}
191
191
  )
@@ -195,7 +195,6 @@ var createBorderCss = (theme) => (variant, directions) => {
195
195
  };
196
196
  function border(theme) {
197
197
  const borderTypes = keyof(theme.border);
198
- const borderCss = createBorderCss(theme);
199
198
  const borderObject = defineConstantProperties(
200
199
  {},
201
200
  {
@@ -204,7 +203,7 @@ function border(theme) {
204
203
  borderTypes,
205
204
  (variant) => definePropertyChains(
206
205
  borderDirections,
207
- (modifiers) => borderCss(variant, modifiers)
206
+ (modifiers) => createBorderCss(variant, modifiers)
208
207
  )
209
208
  )
210
209
  }
@@ -213,12 +212,12 @@ function border(theme) {
213
212
  }
214
213
 
215
214
  // src/builders/borderRadius.ts
216
- var import_utils2 = require("@charcoal-ui/utils");
215
+ var import_utils3 = require("@charcoal-ui/utils");
217
216
  var createBorderRadiusCss = (theme) => (size2) => {
218
217
  return createInternal({
219
218
  toCSS() {
220
219
  return {
221
- borderRadius: (0, import_utils2.px)(theme.borderRadius[size2])
220
+ borderRadius: (0, import_utils3.px)(theme.borderRadius[size2])
222
221
  };
223
222
  }
224
223
  });
@@ -235,14 +234,14 @@ function borderRadius(theme) {
235
234
  }
236
235
 
237
236
  // src/builders/colors.ts
238
- var import_utils4 = require("@charcoal-ui/utils");
237
+ var import_utils5 = require("@charcoal-ui/utils");
239
238
  var import_warning = __toESM(require("warning"));
240
239
 
241
240
  // src/builders/transition.ts
242
- var import_utils3 = require("@charcoal-ui/utils");
241
+ var import_utils4 = require("@charcoal-ui/utils");
243
242
  var TRANSITION_DURATION = 0.2;
244
243
  function transition(_theme) {
245
- const duration = (0, import_utils3.dur)(TRANSITION_DURATION);
244
+ const duration = (0, import_utils4.dur)(TRANSITION_DURATION);
246
245
  const transition2 = (property) => ({
247
246
  transition: property.map((v) => `${duration} ${v}`).join(", ")
248
247
  });
@@ -270,14 +269,14 @@ var createColorCss = (_theme) => (target, color, effects = []) => {
270
269
  function toCSS() {
271
270
  return {
272
271
  [targetProperty(target)]: variable(
273
- (0, import_utils4.customPropertyToken)(color.toString())
272
+ (0, import_utils5.customPropertyToken)(color.toString())
274
273
  ),
275
274
  ...effects.filter(isSupportedEffect).reduce(
276
275
  (acc, effect) => ({
277
276
  ...acc,
278
277
  ...onEffectPseudo(effect, {
279
278
  [targetProperty(target)]: variable(
280
- (0, import_utils4.customPropertyToken)(color.toString(), [effect])
279
+ (0, import_utils5.customPropertyToken)(color.toString(), [effect])
281
280
  )
282
281
  })
283
282
  }),
@@ -295,10 +294,10 @@ var createColorCss = (_theme) => (target, color, effects = []) => {
295
294
  });
296
295
  };
297
296
  var createGradientColorCss = (theme) => (color, effects = [], direction) => {
298
- const toLinearGradient = (0, import_utils4.gradient)(direction);
297
+ const toLinearGradient = (0, import_utils5.gradient)(direction);
299
298
  function toCSS(context) {
300
299
  const optimized = !shouldCancelHalfLeading(context);
301
- const duration = (0, import_utils4.dur)(TRANSITION_DURATION);
300
+ const duration = (0, import_utils5.dur)(TRANSITION_DURATION);
302
301
  if (optimized && effects.length > 0) {
303
302
  return {
304
303
  position: "relative",
@@ -319,7 +318,7 @@ var createGradientColorCss = (theme) => (color, effects = [], direction) => {
319
318
  },
320
319
  ...onEffectPseudo(effect, {
321
320
  "&::before": {
322
- backgroundColor: (0, import_utils4.applyEffect)(
321
+ backgroundColor: (0, import_utils5.applyEffect)(
323
322
  null,
324
323
  theme.effect[effect] ?? []
325
324
  )
@@ -341,7 +340,7 @@ var createGradientColorCss = (theme) => (color, effects = [], direction) => {
341
340
  ...acc,
342
341
  ...onEffectPseudo(effect, {
343
342
  ...toLinearGradient(
344
- (0, import_utils4.applyEffectToGradient)(theme.effect[effect] ?? [])(
343
+ (0, import_utils5.applyEffectToGradient)(theme.effect[effect] ?? [])(
345
344
  theme.gradientColor[color]
346
345
  )
347
346
  )
@@ -431,17 +430,17 @@ function elementEffect(theme) {
431
430
  }
432
431
 
433
432
  // src/builders/outline.ts
434
- var import_utils5 = require("@charcoal-ui/utils");
433
+ var import_utils6 = require("@charcoal-ui/utils");
435
434
  var outlineType = ["focus"];
436
435
  var outlineCss = (weight, color) => ({
437
- boxShadow: `0 0 0 ${(0, import_utils5.px)(weight)} ${color}`
436
+ boxShadow: `0 0 0 ${(0, import_utils6.px)(weight)} ${color}`
438
437
  });
439
438
  var createOutlineColorCss = (theme) => (variant, modifiers) => {
440
439
  const weight = theme.outline[variant].weight;
441
440
  const color = theme.outline[variant].color;
442
441
  return createInternal({
443
442
  toCSS() {
444
- return modifiers.includes("focus") ? onFocus(outlineCss(weight, color)) : { "&&": { [import_utils5.notDisabledSelector]: outlineCss(weight, color) } };
443
+ return modifiers.includes("focus") ? onFocus(outlineCss(weight, color)) : { "&&": { [import_utils6.notDisabledSelector]: outlineCss(weight, color) } };
445
444
  },
446
445
  context: {
447
446
  boxShadowTransition: true
@@ -449,7 +448,7 @@ var createOutlineColorCss = (theme) => (variant, modifiers) => {
449
448
  });
450
449
  };
451
450
  var onFocus = (css2) => ({
452
- [import_utils5.notDisabledSelector]: {
451
+ [import_utils6.notDisabledSelector]: {
453
452
  "&:focus, &:active": {
454
453
  outline: "none",
455
454
  ...css2
@@ -483,12 +482,12 @@ function outline(theme) {
483
482
 
484
483
  // src/builders/size.ts
485
484
  var import_foundation = require("@charcoal-ui/foundation");
486
- var import_utils6 = require("@charcoal-ui/utils");
485
+ var import_utils7 = require("@charcoal-ui/utils");
487
486
  var fixedProperties = ["width", "height"];
488
487
  var createFixedPxCss = (theme) => (property, size2) => createInternal({
489
488
  toCSS() {
490
489
  return {
491
- [property]: size2 === "auto" ? "auto" : (0, import_utils6.px)(theme.spacing[size2])
490
+ [property]: size2 === "auto" ? "auto" : (0, import_utils7.px)(theme.spacing[size2])
492
491
  };
493
492
  }
494
493
  });
@@ -502,7 +501,7 @@ var createFixedRelativeCss = (_theme) => (property, amount) => createInternal({
502
501
  var createFixedColumnCss = (theme) => (property, span) => createInternal({
503
502
  toCSS() {
504
503
  return {
505
- [property]: (0, import_utils6.px)(
504
+ [property]: (0, import_utils7.px)(
506
505
  (0, import_foundation.columnSystem)(span, theme.grid.unit.column, theme.grid.unit.gutter)
507
506
  )
508
507
  };
@@ -529,7 +528,7 @@ function size(theme) {
529
528
  }
530
529
 
531
530
  // src/builders/spacing.ts
532
- var import_utils7 = require("@charcoal-ui/utils");
531
+ var import_utils8 = require("@charcoal-ui/utils");
533
532
  var spacingProperties = ["margin", "padding"];
534
533
  var spacingDirections = [
535
534
  "top",
@@ -568,20 +567,20 @@ var createSpacingCss = (theme) => (property, modifiers) => {
568
567
  function toCSS({ cancelHalfLeadingPx = 0 }) {
569
568
  return {
570
569
  ...top !== void 0 && {
571
- [spacingProperty(property, "top")]: top === "auto" ? "auto" : (0, import_utils7.px)(
570
+ [spacingProperty(property, "top")]: top === "auto" ? "auto" : (0, import_utils8.px)(
572
571
  theme.spacing[top] + (hasVerticalPadding ? cancelHalfLeadingPx : 0)
573
572
  )
574
573
  },
575
574
  ...bottom !== void 0 && {
576
- [spacingProperty(property, "bottom")]: bottom === "auto" ? "auto" : (0, import_utils7.px)(
575
+ [spacingProperty(property, "bottom")]: bottom === "auto" ? "auto" : (0, import_utils8.px)(
577
576
  theme.spacing[bottom] + (hasVerticalPadding ? cancelHalfLeadingPx : 0)
578
577
  )
579
578
  },
580
579
  ...right !== void 0 && {
581
- [spacingProperty(property, "right")]: right === "auto" ? "auto" : (0, import_utils7.px)(theme.spacing[right])
580
+ [spacingProperty(property, "right")]: right === "auto" ? "auto" : (0, import_utils8.px)(theme.spacing[right])
582
581
  },
583
582
  ...left !== void 0 && {
584
- [spacingProperty(property, "left")]: left === "auto" ? "auto" : (0, import_utils7.px)(theme.spacing[left])
583
+ [spacingProperty(property, "left")]: left === "auto" ? "auto" : (0, import_utils8.px)(theme.spacing[left])
585
584
  }
586
585
  };
587
586
  }
@@ -605,7 +604,7 @@ function spacing(theme) {
605
604
  }
606
605
 
607
606
  // src/builders/typography.ts
608
- var import_utils8 = require("@charcoal-ui/utils");
607
+ var import_utils9 = require("@charcoal-ui/utils");
609
608
  var createTypographyCss = (theme) => (size2, options = {}) => {
610
609
  const {
611
610
  preserveHalfLeading = false,
@@ -613,11 +612,11 @@ var createTypographyCss = (theme) => (size2, options = {}) => {
613
612
  bold = false
614
613
  } = options;
615
614
  const descriptor = theme.typography.size[size2];
616
- const margin = -(0, import_utils8.halfLeading)(descriptor);
615
+ const margin = -(0, import_utils9.halfLeading)(descriptor);
617
616
  function toCSS(context) {
618
617
  return {
619
- fontSize: (0, import_utils8.px)(descriptor.fontSize),
620
- lineHeight: (0, import_utils8.px)(descriptor.lineHeight),
618
+ fontSize: (0, import_utils9.px)(descriptor.fontSize),
619
+ lineHeight: (0, import_utils9.px)(descriptor.lineHeight),
621
620
  ...monospace && {
622
621
  fontFamily: "monospace"
623
622
  },
@@ -628,11 +627,11 @@ var createTypographyCss = (theme) => (size2, options = {}) => {
628
627
  display: "flow-root",
629
628
  "&::before": {
630
629
  ...leadingCancel,
631
- marginTop: (0, import_utils8.px)(margin)
630
+ marginTop: (0, import_utils9.px)(margin)
632
631
  },
633
632
  "&::after": {
634
633
  ...leadingCancel,
635
- marginBottom: (0, import_utils8.px)(margin)
634
+ marginBottom: (0, import_utils9.px)(margin)
636
635
  }
637
636
  }
638
637
  };
@@ -689,6 +688,7 @@ function createO(theme) {
689
688
  // src/TokenInjector.tsx
690
689
  var import_react = __toESM(require("react"));
691
690
  var import_styled_components = require("styled-components");
691
+ var import_utils10 = require("@charcoal-ui/utils");
692
692
  var GlobalStyle = import_styled_components.createGlobalStyle`
693
693
  ${({
694
694
  themeMap,
@@ -720,7 +720,17 @@ function TokenInjector({
720
720
  }) {
721
721
  return /* @__PURE__ */ import_react.default.createElement(GlobalStyle, { themeMap, background });
722
722
  }
723
- var defineColorVariableCSS = (theme) => Object.entries(defineThemeVariables(theme.color)({ theme })).map(([varName, value]) => variableDefinition(varName, value.toString())).join(";");
723
+ var defineColorVariableCSS = (theme) => {
724
+ const borders = (0, import_utils10.mapObject)(theme.border, (name, { color }) => [
725
+ withPrefixes("border", name),
726
+ color
727
+ ]);
728
+ const colors2 = defineThemeVariables({ ...theme.color, ...borders })({ theme });
729
+ return toCSSVariables(colors2);
730
+ };
731
+ function toCSSVariables(css2) {
732
+ return Object.entries(css2).map(([varName, value]) => variableDefinition(varName, value.toString())).join(";");
733
+ }
724
734
  var variableDefinition = (prop, value) => `${prop}: ${value}`;
725
735
 
726
736
  // src/helper.ts