@salty-css/react
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-alpha.0 • Public • Published

Salty Css

Basic usage example with Button

Initial requirements

  1. Add saltyPlugin to vite or webpack config from @salty-css/vite or @salty-css/webpack
  2. Create salty-config.ts to the root of your project
  3. Import global styles to any regular .css file from saltygen/index.css (does not exist during first run, cli command coming later)
  4. Create salty components with styled only inside files that end with .css.ts, .salty.ts .styled.ts or .styles.ts

Code examples

Salty config

import { defineConfig } from '@salty-css/core/config';

export const config = defineConfig({
  variables: {
    colors: {
      brand: '#111',
      highlight: 'yellow',
    },
  },
  global: {
    html: {
      backgroundColor: '#f8f8f8',
    },
  },
});

Your React component file

import { Wrapper } from '../components/wrapper/wrapper.css';
import { Button } from '../components/button/button.css';

export const IndexPage = () => {
  return (
    <Wrapper>
      <Button variant="solid" onClick={() => alert('It is a button.')}>
        Outlined
      </Button>
    </Wrapper>
  );
};

Wrapper (components/wrapper/wrapper.css.ts)

import { styled } from '@salty-css/react/styled';

export const Wrapper = styled('div', {
  display: 'block',
  padding: '2vw',
});

Button (components/button/button.css.ts)

import { styled } from '@salty-css/react/styled';

export const Button = styled('button', {
  display: 'block',
  padding: `0.6em 1.2em`,
  border: '1px solid currentColor',
  background: 'transparent',
  color: 'currentColor/40',
  cursor: 'pointer',
  transition: '200ms',
  textDecoration: 'none',
  '&:hover': {
    background: 'black',
    borderColor: 'black',
    color: 'white',
  },
  '&:disabled': {
    opacity: 0.25,
    pointerEvents: 'none',
  },
  variants: {
    variant: {
      outlined: {
        // same as default styles
      },
      solid: {
        '&:not(:hover)': {
          background: 'black',
          borderColor: 'black',
          color: 'white',
        },
        '&:hover': {
          background: 'transparent',
          borderColor: 'currentColor',
          color: 'currentColor',
        },
      },
    },
  },
});

More examples coming soon

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.1-alpha.0108latest
0.0.1-alpha.1239dev

Version History

VersionDownloads (Last 7 Days)Published
0.0.1-alpha.1239
0.0.1-alpha.1145
0.0.1-alpha.1042
0.0.1-alpha.948
0.0.1-alpha.857
0.0.1-alpha.750
0.0.1-alpha.653
0.0.1-alpha.551
0.0.1-alpha.444
0.0.1-alpha.343
0.0.1-alpha.247
0.0.1-alpha.146
0.0.1-alpha.0108

Package Sidebar

Install

npm i @salty-css/react

Weekly Downloads

673

Version

0.0.1-alpha.0

License

MIT

Unpacked Size

3.17 kB

Total Files

2

Last publish

Collaborators

  • tremppu