@onfido/castor
Advanced tools
Comparing version 1.0.0-rc.1 to 1.0.0-rc.2
export * from './components'; | ||
export * from './core'; | ||
export * from './helpers'; | ||
export * from './theme'; | ||
export * from './utils'; | ||
//# sourceMappingURL=index.js.map |
@@ -16,51 +16,31 @@ /** | ||
*/ | ||
export const classy = (...classNames) => classNames | ||
.flat(10) | ||
.flatMap((className) => className instanceof Object ? getTruthyKeys(className) : className) | ||
.filter(Boolean) | ||
.join(' '); | ||
export const classy = (...classNames) => classNames.flat(10).flatMap(truthyNames).join(' '); | ||
/** | ||
* Prefixes component names with a predetermined identifier. | ||
* | ||
* Can be used as tagged template literal, separated by spaces. | ||
* | ||
* @param components Names to prefix. | ||
* | ||
* @example | ||
* c('button') || c`button`; | ||
* c('button'); | ||
* // ['ods-button'] | ||
*/ | ||
export const c = mapWithPrefix('ods-'); | ||
export const c = withPrefix('ods-'); | ||
/** | ||
* Prefixes modifier names with a predetermined identifier. | ||
* | ||
* Can be used as tagged template literal, separated by spaces. | ||
* | ||
* @param modifiers Names to prefix. | ||
* | ||
* @example | ||
* m('action', 'primary') || m`action primary`; | ||
* m('action', 'primary'); | ||
* // ['-action', '-primary'] | ||
*/ | ||
export const m = mapWithPrefix('-'); | ||
const fromTemplate = (array) => isTemplate(array) | ||
? array[0] | ||
.map((value, i) => value + classy(array[i + 1])) | ||
.join('') | ||
.split(' ') | ||
: array; | ||
const getTruthyKeys = (obj) => Object.entries(obj) | ||
.filter(([, value]) => !!value) | ||
.map(([key]) => key); | ||
const isTemplate = (template) => Array.isArray(template[0]) && | ||
Array.isArray(template[0].raw); | ||
const mapKey = (obj, mapFn) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [mapFn(key), value])); | ||
function mapWithPrefix(prefix) { | ||
return (...array) => fromTemplate(array) | ||
.flat(10) | ||
.filter(Boolean) | ||
.flatMap((className) => className instanceof Object | ||
? getTruthyKeys(mapKey(className, (key) => `${prefix}${key}`)) | ||
: `${prefix}${className}`); | ||
export const m = withPrefix('-'); | ||
const truthyNames = (value) => (value instanceof Object | ||
? Object.entries(value) | ||
.filter(([, value]) => !!value) | ||
.map(([key]) => key) | ||
: [value]).filter(Boolean); | ||
function withPrefix(prefix) { | ||
return (...classNames) => classNames.flatMap(truthyNames).map((name) => `${prefix}${name}`); | ||
} | ||
//# sourceMappingURL=classy.js.map |
export * from './classy/classy'; | ||
export * from './dashCase/dashCase'; | ||
export * from './kebabCase/kebabCase'; | ||
export * from './toCSS/toCSS'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { dashCase } from '../../utils'; | ||
import { kebabCase } from '../../utils'; | ||
/** | ||
@@ -8,5 +8,5 @@ * Transforms a `Font` style object into a valid CSS string. | ||
export const toCSS = (font) => Object.entries(font) | ||
.map(([key, value]) => `${dashCase(key)}: ${value};`) | ||
.map(([key, value]) => `${kebabCase(key)}: ${value};`) | ||
.join('\n') | ||
.replace(/"|'/g, ''); | ||
//# sourceMappingURL=toCSS.js.map |
{ | ||
"name": "@onfido/castor", | ||
"version": "1.0.0-rc.1", | ||
"version": "1.0.0-rc.2", | ||
"description": "Onfido's design system.", | ||
@@ -5,0 +5,0 @@ "author": "Onfido", |
@@ -115,4 +115,4 @@ # Castor · [![npm version](https://img.shields.io/npm/v/@onfido/castor.svg?style=flat-square)](https://www.npmjs.com/package/@onfido/castor) | ||
@include castor.day-class(); | ||
@include castor.night-class(); | ||
@include castor.day('class'); | ||
@include castor.night('class'); | ||
``` | ||
@@ -136,2 +136,15 @@ | ||
Lastly, if you're extremely concerned about efficiency, you can shave off 1-3 KBs by not including base tokens twice, if they're shared between the themes you're switching: | ||
```scss | ||
@use '~@onfido/castor'; | ||
:root { | ||
@include castor.tokens(); | ||
} | ||
@include castor.day('class', 'raw'); | ||
@include castor.night('class', 'raw'); | ||
``` | ||
## Use components | ||
@@ -153,3 +166,3 @@ | ||
.ods-button.round { | ||
border-radius: var(--border-radius-full); | ||
border-radius: var(--ods-border-radius-full); | ||
} | ||
@@ -156,0 +169,0 @@ ``` |
import { IconName } from '@onfido/castor-icons'; | ||
import { Color } from '../../core'; | ||
import { Color } from '../../helpers'; | ||
@@ -4,0 +4,0 @@ export interface IconProps { |
export * from './components'; | ||
export * from './core'; | ||
export * from './helpers'; | ||
export * from './theme'; | ||
export * from './utils'; |
export type ClassName = string | null | undefined; | ||
export type ClassNameRecord = Record<string, boolean | null | undefined>; | ||
export type ClassNames = ClassName | ClassName[] | ClassNameRecord; | ||
type Template = [TemplateStringsArray, ...ClassNames[]]; | ||
@@ -22,9 +21,3 @@ /** | ||
export const classy = (...classNames: ClassNames[]) => | ||
classNames | ||
.flat(10) | ||
.flatMap((className) => | ||
className instanceof Object ? getTruthyKeys(className) : className | ||
) | ||
.filter(Boolean) | ||
.join(' '); | ||
classNames.flat(10).flatMap(truthyNames).join(' '); | ||
@@ -34,11 +27,9 @@ /** | ||
* | ||
* Can be used as tagged template literal, separated by spaces. | ||
* | ||
* @param components Names to prefix. | ||
* | ||
* @example | ||
* c('button') || c`button`; | ||
* c('button'); | ||
* // ['ods-button'] | ||
*/ | ||
export const c = mapWithPrefix('ods-'); | ||
export const c = withPrefix('ods-'); | ||
@@ -48,47 +39,21 @@ /** | ||
* | ||
* Can be used as tagged template literal, separated by spaces. | ||
* | ||
* @param modifiers Names to prefix. | ||
* | ||
* @example | ||
* m('action', 'primary') || m`action primary`; | ||
* m('action', 'primary'); | ||
* // ['-action', '-primary'] | ||
*/ | ||
export const m = mapWithPrefix('-'); | ||
export const m = withPrefix('-'); | ||
const fromTemplate = (array: Template | ClassNames[]) => | ||
isTemplate(array) | ||
? array[0] | ||
.map((value, i) => value + classy(array[i + 1] as ClassNames)) | ||
.join('') | ||
.split(' ') | ||
: array; | ||
const truthyNames = (value: ClassName | ClassNameRecord) => | ||
(value instanceof Object | ||
? Object.entries(value) | ||
.filter(([, value]) => !!value) | ||
.map(([key]) => key) | ||
: [value] | ||
).filter(Boolean); | ||
const getTruthyKeys = (obj: Record<string, unknown>): string[] => | ||
Object.entries(obj) | ||
.filter(([, value]) => !!value) | ||
.map(([key]) => key); | ||
const isTemplate = (template: Template | unknown[]): template is Template => | ||
Array.isArray(template[0]) && | ||
Array.isArray(((template[0] as unknown) as TemplateStringsArray).raw); | ||
const mapKey = <V>( | ||
obj: Record<string, V>, | ||
mapFn: (key: string) => string | ||
): Record<string, V> => | ||
Object.fromEntries( | ||
Object.entries(obj).map(([key, value]) => [mapFn(key), value]) | ||
); | ||
function mapWithPrefix(prefix: string) { | ||
return (...array: ClassNames[] | Template) => | ||
fromTemplate(array) | ||
.flat(10) | ||
.filter(Boolean) | ||
.flatMap((className) => | ||
className instanceof Object | ||
? getTruthyKeys(mapKey(className, (key) => `${prefix}${key}`)) | ||
: `${prefix}${className}` | ||
); | ||
function withPrefix(prefix: string) { | ||
return (...classNames: (ClassName | ClassNameRecord)[]) => | ||
classNames.flatMap(truthyNames).map((name) => `${prefix}${name}`); | ||
} |
export * from './classy/classy'; | ||
export * from './dashCase/dashCase'; | ||
export * from './kebabCase/kebabCase'; | ||
export * from './toCSS/toCSS'; |
@@ -1,3 +0,3 @@ | ||
import { Font } from '../../core/helpers'; | ||
import { dashCase } from '../../utils'; | ||
import { Font } from '../../helpers'; | ||
import { kebabCase } from '../../utils'; | ||
@@ -11,4 +11,4 @@ /** | ||
Object.entries(font) | ||
.map(([key, value]) => `${dashCase(key)}: ${value};`) | ||
.map(([key, value]) => `${kebabCase(key)}: ${value};`) | ||
.join('\n') | ||
.replace(/"|'/g, ''); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
99167
85
181
751
1