0.2.0 • Published 5 years ago

@nju33/styled-components v0.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

@nju33/styled-components

github npm:version typescript ci:status document:typedoc license code style:prettier

My styled-components helpers

Usage

/**
 * Before, To install this and styled-components
 * ```bash
 * yarn add @nju33/styled-components styled-components @types/styled-components
 * ```
 */
import {Mixin, RequiredAtomProps, createMedia} from '@nju33/styled-components';

Example

const foo = 'foo' as 'foo';
const bar = 'bar' as 'bar';

type MixinName = typeof foo | typeof bar;
type CurrentComponentMixin = Mixin<MixinName>;

const mixin: CurrentComponentMixin = (mixinName => (
  first,
  ...interpolations
) => css`
  &.${mixinName} {
    ${css(first, ...interpolations)}
  }
`) as CurrentComponentMixin;

mixin[foo] = mixin(foo)`
  font-size: 15px;
`;

mixin[bar] = mixin(bar)`
  font-size: 13;
`;

// tslint:disable-next-line:no-unused-expression
styled.div<RequiredAtomProps<MixinName>>`
  ${mixin.foo};
  ${mixin.bar};
`;
interface Sizes {
	desktop: number;
	tablet: number;
	phone: number;
}

const media = createMedia<Sizes>({
	desktop 992,
	tablet: 768,
	phone: 576
});

styled.div`
	color: blue;

	${media.desktop`
		color: orange;
	`};
`;
// color: blue;
// @media screen and (min-width: 992px) {
//   color: orange;
// }
0.2.0

5 years ago

0.0.5

5 years ago