From 771b7941a6d598e5054ac1d5184cdf806457a9be Mon Sep 17 00:00:00 2001 From: Daniel Del Core Date: Sat, 20 Feb 2021 20:52:35 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Configuration=20for=20macro=20re?= =?UTF-8?q?factor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .storybook/main.js | 2 +- examples/Macro.tsx | 196 +++++++++++++++++++++++++++++++++++++ packages/core/src/index.ts | 1 + packages/macro/README.md | 2 +- 4 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 examples/Macro.tsx diff --git a/.storybook/main.js b/.storybook/main.js index c9c6b71..ece7635 100644 --- a/.storybook/main.js +++ b/.storybook/main.js @@ -1,4 +1,4 @@ module.exports = { - stories: ['../examples/**/*.(js|jsx|ts|tsx)'], + stories: ['../examples/**/*.@(js|jsx|ts|tsx|mdx)'], addons: ['storybook-addon-performance'], }; diff --git a/examples/Macro.tsx b/examples/Macro.tsx new file mode 100644 index 0000000..a354767 --- /dev/null +++ b/examples/Macro.tsx @@ -0,0 +1,196 @@ +import React, { FC, Fragment, ReactNode, useState } from 'react'; +import { storiesOf } from '@storybook/react'; + +import { css } from '@trousers/macro'; + +storiesOf('Macro', module) + .add('Elements and modifiers', () => { + interface ButtonProps { + children: ReactNode; + primary?: boolean; + disabled?: boolean; + } + + const styles = css('button', { + backgroundColor: '#b3cde8', + borderRadius: '6px', + border: 'none', + boxShadow: 'inset 0 -4px #9fb8d1', + color: 'white', + display: 'inline-block', + cursor: 'pointer', + fontFamily: 'sans-serif', + fontWeight: 'normal', + fontSize: '20px', + letterSpacing: '1px', + margin: '5px 10px', + padding: '10px 20px 14px 20px', + textDecoration: 'none', + transition: 'background-color 300ms, color 300ms', + outline: 'none', + ':hover': { + backgroundColor: '#adc6e0', + color: 'rgba(255, 255, 255, 0.8)', + }, + ':active': { + backgroundColor: '#9fb8d1', + }, + }) + .modifier('primary', { + backgroundColor: '#f95b5b', + boxShadow: 'inset 0 -4px #c54646', + color: '#ffffff', + ':hover': { + backgroundColor: '#e45454', + }, + ':active': { + backgroundColor: '#c54646', + }, + }) + .modifier('disabled', { + backgroundColor: '#efefef', + boxShadow: 'inset 0 -4px #afafaf', + color: '#afafaf', + cursor: 'not-allowed', + '&:hover,&:active': { + color: '#afafaf', + backgroundColor: '#efefef', + }, + }); + + const Button: FC = ({ primary, disabled, children }) => ( + + ); + + return ( + + + + + + + ); + }) + .add('Modifiers and state', () => { + const toggleStyles = css('button', { + backgroundColor: '#b3cde8', + borderRadius: '6px', + border: 'none', + boxShadow: 'inset 0 -4px #9fb8d1', + color: 'white', + display: 'inline-block', + cursor: 'pointer', + fontFamily: 'sans-serif', + fontWeight: 'normal', + fontSize: '20px', + letterSpacing: '1px', + margin: '5px 10px', + padding: '10px 20px 14px 20px', + textDecoration: 'none', + outline: 'none', + ':hover': { + backgroundColor: '#adc6e0', + color: 'rgba(255, 255, 255, 0.8)', + }, + ':active': { + backgroundColor: '#9fb8d1', + }, + }).modifier('isOn', { + backgroundColor: '#f95b5b', + boxShadow: 'inset 0 -4px #c54646', + color: '#ffffff', + ':hover': { + backgroundColor: '#e45454', + }, + ':active': { + backgroundColor: '#c54646', + }, + }); + + const Button: FC = () => { + const [isOn, setToggle] = useState(false); + + return ( + + ); + }; + + return