@pluralsight/headless-styles
Advanced tools
Comparing version 0.0.0-experimental-c60e41-20220321 to 0.0.0-experimental-d04cd0-20220405
import { getDefaultOptions } from './shared'; | ||
import styles from './buttonCSS.module.css'; | ||
export function getButtonProps(options) { | ||
const { kind, size } = getDefaultOptions(options); | ||
var _a; | ||
const { kind, size, tech } = getDefaultOptions(options); | ||
const formattedSize = `size-${size}`; | ||
const framework = (_a = styles[tech]) !== null && _a !== void 0 ? _a : ''; | ||
return { | ||
className: `ps-btn ${styles.base} ${styles[kind]} ${styles[formattedSize]}`, | ||
className: `ps-btn ${styles.base} ${styles[kind]} ${styles[formattedSize]} ${framework}`, | ||
type: 'button', | ||
}; | ||
} |
import { psBackground, psBackgroundActive, psBackgroundHover, psBackgroundWeak, psNeutralBackground, psNeutralBackgroundActive, psNeutralBackgroundHover, psNeutralText, psNeutralTextWeak, psText, psTextMedium, } from '@pluralsight/design-tokens'; | ||
import { getDefaultOptions } from './shared'; | ||
const buttonStyles = { | ||
appearance: 'none', | ||
borderRadius: '6px', | ||
backgroundColor: 'transparent', | ||
border: 'none', | ||
cursor: 'pointer', | ||
fontSize: '16px', | ||
padding: '10px 16px', | ||
textAlign: 'center', | ||
textDecoration: 'none', | ||
transition: 'background-color 250ms ease-in-out, color 250ms ease-in-out', | ||
active: { | ||
outline: 'none', | ||
}, | ||
focus: { | ||
import { transformStyles } from '../../utils/helpers'; | ||
import styles from './generated/buttonCSS.module'; | ||
const baseStyles = Object.assign(Object.assign({}, styles.base), { '&:focus': { | ||
outline: `3px solid ${psBackgroundActive}`, | ||
}, | ||
focusNotFocusVisible: { | ||
boxShadow: 'none', | ||
outline: 0, | ||
}, | ||
}; | ||
const baseCSSProps = ` | ||
appearance: none; | ||
background-color: transparent; | ||
border: none; | ||
border-radius: 6px; | ||
cursor: pointer; | ||
text-align: center; | ||
text-decoration: none; | ||
transition: background-color 250ms ease-in-out, color 250ms ease-in-out; | ||
&:active { | ||
outline: none; | ||
} | ||
&:focus { | ||
outline: 3px solid ${psBackgroundActive}; | ||
} | ||
&:focus:not(:focus-visible) { | ||
box-shadow: none; | ||
outline: 0; | ||
} | ||
`; | ||
} }); | ||
function getKindStyles(kind) { | ||
switch (kind) { | ||
case 'text-weak': | ||
return { | ||
css: ` | ||
color: ${psTextMedium}; | ||
`, | ||
js: { | ||
color: psTextMedium, | ||
}, | ||
}; | ||
return Object.assign(Object.assign({}, styles.text_weak), { color: psTextMedium, '&:active': { | ||
backgroundColor: psBackgroundActive, | ||
}, '&:hover': { | ||
backgroundColor: psBackgroundHover, | ||
color: '#fff', | ||
} }); | ||
case 'weak': | ||
return { | ||
css: ` | ||
background-color: ${psNeutralBackground}; | ||
color: ${psNeutralText}; | ||
`, | ||
js: { | ||
backgroundColor: psNeutralBackground, | ||
color: psNeutralText, | ||
}, | ||
}; | ||
return Object.assign(Object.assign({}, styles.weak), { backgroundColor: psNeutralBackground, color: psNeutralText, '&:active': { | ||
backgroundColor: psNeutralBackgroundActive, | ||
}, '&:hover': { | ||
backgroundColor: psNeutralBackgroundHover, | ||
} }); | ||
case 'medium': | ||
return { | ||
css: ` | ||
background-color: ${psBackground}; | ||
color: #fff; | ||
`, | ||
js: { | ||
backgroundColor: psBackground, | ||
return Object.assign(Object.assign({}, styles.medium), { backgroundColor: psBackground, '&:active': { | ||
backgroundColor: psBackgroundActive, | ||
}, '&:hover': { | ||
backgroundColor: psBackgroundHover, | ||
color: '#fff', | ||
}, | ||
}; | ||
} }); | ||
case 'strong': | ||
return { | ||
css: ` | ||
background-color: ${psBackgroundWeak}; | ||
color: ${psText}; | ||
`, | ||
js: { | ||
backgroundColor: psBackgroundWeak, | ||
color: psText, | ||
}, | ||
}; | ||
return Object.assign(Object.assign({}, styles.strong), { backgroundColor: psBackgroundWeak, color: psText, '&:active': { | ||
backgroundColor: psBackgroundActive, | ||
}, '&:hover': { | ||
backgroundColor: psBackgroundHover, | ||
color: '#fff', | ||
} }); | ||
default: | ||
return { | ||
css: ` | ||
color: ${psNeutralTextWeak}; | ||
`, | ||
js: { | ||
color: psNeutralTextWeak, | ||
}, | ||
}; | ||
return Object.assign(Object.assign({}, styles.text), { color: psNeutralTextWeak, '&:active': { | ||
backgroundColor: psBackgroundActive, | ||
}, '&:hover': { | ||
backgroundColor: psNeutralBackgroundHover, | ||
color: '#fff', | ||
} }); | ||
} | ||
} | ||
function getSizeStyles(size) { | ||
switch (size) { | ||
case 'xs': | ||
return { | ||
css: ` | ||
font-size: 12px; | ||
padding: 4px 8px; | ||
`, | ||
js: { | ||
fontSize: '12px', | ||
padding: '4px 8px', | ||
}, | ||
}; | ||
case 's': | ||
return { | ||
css: ` | ||
font-size: 14px; | ||
padding: 6px 12px; | ||
`, | ||
js: { | ||
fontSize: '14px', | ||
padding: '6px 12px', | ||
}, | ||
}; | ||
case 'l': | ||
return { | ||
css: ` | ||
font-size: 16px; | ||
padding: 14.5px 24px; | ||
`, | ||
js: { | ||
fontSize: '16px', | ||
padding: '14.5px 24px', | ||
}, | ||
}; | ||
default: | ||
return { | ||
css: ` | ||
font-size: 16px; | ||
padding: 10px 16px; | ||
`, | ||
js: { | ||
fontSize: '16px', | ||
padding: '10px 16px', | ||
}, | ||
}; | ||
} | ||
} | ||
function getPsuedoStyles(kind) { | ||
switch (kind) { | ||
case 'text-weak': | ||
case 'medium': | ||
case 'strong': | ||
return { | ||
css: ` | ||
&:hover { | ||
color: #fff; | ||
background-color: ${psBackgroundHover}; | ||
} | ||
&:active { | ||
background-color: ${psBackgroundActive}; | ||
} | ||
`, | ||
js: { | ||
hover: { | ||
color: '#fff', | ||
backgroundColor: psBackgroundHover, | ||
}, | ||
active: { | ||
backgroundColor: psBackgroundActive, | ||
}, | ||
}, | ||
}; | ||
case 'weak': | ||
return { | ||
css: ` | ||
&:hover { | ||
color: #fff; | ||
background-color: ${psNeutralBackgroundHover}; | ||
} | ||
&:active { | ||
background-color: ${psNeutralBackgroundActive}; | ||
} | ||
`, | ||
js: { | ||
hover: { | ||
color: '#fff', | ||
backgroundColor: psNeutralBackgroundHover, | ||
}, | ||
active: { | ||
backgroundColor: psNeutralBackgroundActive, | ||
}, | ||
}, | ||
}; | ||
default: | ||
return { | ||
css: ` | ||
&:hover { | ||
color: #fff; | ||
background-color: ${psNeutralBackgroundHover}; | ||
} | ||
&:active { | ||
background-color: ${psBackgroundActive}; | ||
} | ||
`, | ||
js: { | ||
hover: { | ||
color: '#fff', | ||
backgroundColor: psNeutralBackgroundHover, | ||
}, | ||
active: { | ||
backgroundColor: psBackgroundActive, | ||
}, | ||
}, | ||
}; | ||
} | ||
} | ||
export function getJSButtonProps(options) { | ||
const { kind, size } = getDefaultOptions(options); | ||
const kindStyles = getKindStyles(kind); | ||
const sizeStyles = getSizeStyles(size); | ||
const psuedoStyles = getPsuedoStyles(kind); | ||
const sizeKey = `size_${size}`; | ||
const JsStyles = Object.assign(Object.assign(Object.assign(Object.assign({}, baseStyles), kindStyles), styles[sizeKey]), { '&:active': Object.assign(Object.assign({}, baseStyles['&:active']), kindStyles['&:active']) }); | ||
return { | ||
cssProps: ` | ||
${baseCSSProps} | ||
${kindStyles.css.trim()} | ||
${sizeStyles.css.trim()} | ||
${psuedoStyles.css.trim()} | ||
` | ||
.trim() | ||
.replace(/^ {2,12}/gm, ''), | ||
styles: Object.assign(Object.assign(Object.assign(Object.assign({}, buttonStyles), kindStyles.js), sizeStyles.js), { hover: Object.assign({}, psuedoStyles.js.hover), active: Object.assign(Object.assign({}, buttonStyles.active), psuedoStyles.js.active), focus: Object.assign(Object.assign({}, buttonStyles.focus), buttonStyles.focusNotFocusVisible) }), | ||
cssProps: transformStyles(JsStyles), | ||
styles: JsStyles, | ||
type: 'button', | ||
}; | ||
} |
@@ -1,5 +0,6 @@ | ||
import type { ButtonOptions, Kind, Size } from './types'; | ||
import type { ButtonOptions, Kind, Size, Tech } from './types'; | ||
export declare const defaultButtonOptions: { | ||
kind: Kind; | ||
size: Size; | ||
tech: Tech; | ||
}; | ||
@@ -9,2 +10,3 @@ export declare function getDefaultOptions(options?: ButtonOptions): { | ||
size: Size; | ||
tech: Tech; | ||
}; |
export const defaultButtonOptions = { | ||
kind: 'text', | ||
size: 'm', | ||
tech: '', | ||
}; | ||
export function getDefaultOptions(options) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
return { | ||
kind: (_a = options === null || options === void 0 ? void 0 : options.kind) !== null && _a !== void 0 ? _a : defaultButtonOptions.kind, | ||
size: (_b = options === null || options === void 0 ? void 0 : options.size) !== null && _b !== void 0 ? _b : defaultButtonOptions.size, | ||
tech: (_c = options === null || options === void 0 ? void 0 : options.tech) !== null && _c !== void 0 ? _c : defaultButtonOptions.tech, | ||
}; | ||
} |
@@ -5,2 +5,3 @@ import { ButtonHTMLAttributes, DetailedHTMLProps } from 'react'; | ||
size?: Size; | ||
tech?: Tech; | ||
} | ||
@@ -10,1 +11,2 @@ export declare type ButtonType = 'button' | 'submit' | 'reset' | undefined; | ||
export declare type Size = 'xs' | 's' | 'm' | 'l'; | ||
export declare type Tech = 'chakra' | ''; |
{ | ||
"name": "@pluralsight/headless-styles", | ||
"version": "0.0.0-experimental-c60e41-20220321", | ||
"version": "0.0.0-experimental-d04cd0-20220405", | ||
"description": "Headless styles for Pluralsight.", | ||
"main": "./build/index.js", | ||
"main": "build/common/index.js", | ||
"module": "build/index.js", | ||
"types": "build/index.d.ts", | ||
"files": [ | ||
@@ -13,4 +15,9 @@ "build/**/*" | ||
], | ||
"workspaces": [ | ||
"sandbox" | ||
], | ||
"scripts": { | ||
"build": "yarn copy:css && tsc --project tsconfig.build.json", | ||
"build": "yarn build:common && yarn build:es", | ||
"build:common": "tsc --project tsconfig.cjs.json", | ||
"build:es": "yarn copy:css && tsc --project tsconfig.build.json", | ||
"copy:css": "copyfiles --up 1 ./src/**/*.module.css build", | ||
@@ -20,3 +27,4 @@ "test": "echo \"'yarn test' should be run from root directory.\" && exit 1" | ||
"dependencies": { | ||
"@pluralsight/design-tokens": "alpha" | ||
"@pluralsight/design-tokens": "alpha", | ||
"kebab-case": "^1.0.1" | ||
}, | ||
@@ -23,0 +31,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
182521
31
6633
2
1
+ Addedkebab-case@^1.0.1
+ Addedkebab-case@1.0.2(transitive)