Skip to content

Commit

Permalink
feat: support custom shorthands for rules
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Mar 22, 2020
1 parent a118792 commit 7fb9903
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 5 additions & 1 deletion packages/example/src/components/StyledComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ import React from 'react';
export default function StyledComponent(): JSX.Element {
const sx = useStyling();

return <div {...sx({ p: 4, bg: 'papayawhip' })}>Hello, world!</div>;
return (
<div {...sx({ px: 4, py: 2, bg: 'papayawhip', color: 'rebeccapurple' })}>
Hello, world!
</div>
);
}
20 changes: 12 additions & 8 deletions packages/glaze/src/useStyling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ export default function useStyling(): (
// eslint-disable-next-line guard-for-in, no-restricted-syntax
for (const alias in themedStyle) {
const value = themedStyle[alias];
const key = theme.aliases[alias] || alias;
const shorthand = theme.aliases[alias] || alias;

if (typeof value !== 'object') {
const staticClassName = staticClassNames[`${key}.${value}`];
if (staticClassName) {
className += `${staticClassName} `;
} else {
style[key] = value;
// eslint-disable-next-line no-loop-func
(theme.shorthands[shorthand] || [shorthand]).forEach((key) => {
// TODO: Support selectors and media queries
if (typeof value !== 'object') {
const staticClassName = staticClassNames[`${key}.${value}`];
if (staticClassName) {
className += `${staticClassName} `;
} else {
style[key] = value;
}
}
}
});
}

return { className, style };
Expand Down

0 comments on commit 7fb9903

Please sign in to comment.