GithubHelp home page GithubHelp logo

foliage-ui / foliage Goto Github PK

View Code? Open in Web Editor NEW
28.0 11.0 2.0 2.12 MB

๐Ÿƒ Style your components with performance

Home Page: https://foliage.sova.dev

TypeScript 50.96% HTML 0.21% JavaScript 48.83%
effector forest styled-components styled ui dom foliage

foliage's Introduction

foliage ๐Ÿƒ

GitHub dev.to

Usage with React

Work in progress. Most of this examples are just concept

import { css, component } from 'foliage-react';

const button = css`
  display: inline-block;
  border-radius: 3px;
  padding: 0.5rem 0;
  margin: 0.5rem 1rem;
  width: 11rem;
  border: 2px solid white;
`;

export const Button = component('a', button, {
  defaults: { color: 'default' },
  variants: {
    color: {
      primary: css`
        background: white;
        color: black;
      `,
      default: css`
        background: transparent;
        color: white;
      `,
    },
  },
});

Extending styles

import { css, component } from 'foliage-react';

const button = css`
  color: palevioletred;
  font-size: 1em;
  margin: 1em;
  padding: 0.25em 1em;
  border: 2px solid palevioletred;
  border-radius: 3px;
`;

export const Button = component('button', button);

const tomato = css`
  color: tomato;
  border-color: tomato;
`;

export const TomatoButton = component('button', [button, tomato]);

Pseudoelement, pseudoselectors, and nesting

import { css, component } from 'foliage-react';

const thing = css`
  color: blue;

  &:hover {
    color: red; // <Thing> when hovered
  }

  & ~ & {
    background: tomato; // <Thing> as a sibling of <Thing>, but maybe not directly next to it
  }

  & + & {
    background: lime; // <Thing> next to <Thing>
  }

  &.something {
    background: orange; // <Thing> tagged with an additional CSS class ".something"
  }

  .something-else & {
    border: 1px solid; // <Thing> inside another element labeled ".something-else"
  }
`;

export const Thing = component('div', thing, { attrs: { tabIndex: 0 } });

const Example = () => (
  <>
    <Thing>Hello world!</Thing>
    <Thing>How ya doing?</Thing>
    <Thing className="something">The sun is shining...</Thing>
    <div>Pretty nice day today.</div>
    <Thing>Don't you think?</Thing>
    <div className="something-else">
      <Thing>Splendid.</Thing>
    </div>
  </>
);

Animations

import { css, keyframes, component } from 'foliage-react';

const rotate = keyframes`
  from { transform: rotate(0deg) }
  to { transform: rotate(360deg) }
`;

const block = css`
  display: inline-block;
  animation: ${rotate} 2s linear infinite;
  padding: 2rem 1rem;
  font-size: 1.2rem;
`;

export const Block = component('div', block);

Theming

import { css, keyframes, createGlobalStyle, Global } from 'foliage-react';
const theme = {
  main: '--theme-main',
};

const button = css`
  font-size: 1em;
  margin: 1em;
  padding: 0.25em 1em;
  border-radius: 3px;

  /* Color the border and text with theme.main */
  color: var(${theme.main});
  border: 2px solid var(${theme.main});
`;

const Button = component('button', button);

const primaryTheme = createGlobalStyle`
  :root {
    ${theme.main}: palevioletred;
  }
`;

const secondaryTheme = createGlobalStyle`
  :root {
    ${theme.main}: mediumseagreen;
  }
`;

const Example = () => (
  <>
    <Global styles={primaryTheme} />
    <Button />
  </>
);

Composable components

import { css, component } from 'foliage-react';

const baseStyles = css`
  color: white;
  background-color: mediumseagreen;
  border-radius: 4px;
`;

export const Button = component('button', baseStyles, {
  variants: {
    color: {
      gray: css`
        background-color: gainsboro;
      `,
      blue: css`
        background-color: dodgerblue;
      `,
    },
    size: {
      md: css`
        height: 26px;
      `,
      lg: css`
        height: 36px;
      `,
    },
  },
  compound: [
    {
      color: 'blue',
      size: 'lg',
      css: css`
        background-color: purple;
      `,
    },
  ],
  defaults: {
    color: 'gray',
    size: 'md',
  },
});

Release process

  1. Check out the draft release.
  2. All PRs should have correct labels and useful titles. You can review available labels here.
  3. Update labels for PRs and titles, next manually run the release drafter action to regenerate the draft release.
  4. Review the new version and press "Publish"
  5. If required check "Create discussion for this release"

foliage's People

Contributors

dependabot[bot] avatar drevoed avatar sergeysova avatar zerobias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

foliage's Issues

Support for stores

In React we could use components props and context to create dynamic styles

const Text = styled.div`
  color: ${props => props.color}
`

In Forest we can do something with stores. Simple use case - theming

const Text = styled.div`
  color: ${theme.map(theme => theme.colors.primary)}
`

Now it sets color to [object Object]
image

Tailwind integration

Would be also cool to see tw utility

import { tw } from 'foliage-tailwind'
import { component } from 'foliage-react'

const Button = component("button", {
  defaults: { size: "normal" },
  variants: {
    size: {
      large: tw`px-4 py-2`,
      normal: tw`px-2 py-1`
    }
  }
})

`merge` utility

It would be useful to have some utility to merge configs, so we could create common colors, roundness, padding configs for UI-kit and then combine them in components:

Example:

// ./config/index,ts
export const colors = {
  variants: {
    color: {
      primary: css`
        background: white;
        color: black;
      `,
      default: css`
        background: transparent;
        color: white;
      `,
    },
  },
}

export const sizes = {
  variants: {
    size: {
      large: css`
        padding: 20px 30px;
      `,
      normal: css`
        padding: 10px 20px;
      `
    }
  }
}
// ./components/Button.tsx
import { merge } from 'foliage'
import { component } from 'foliage-react'

import { colors, sizes } from '../config'

export const Button = component("button", merge(colors, sizes), {
  defaults: { color: 'primary', size: 'normal' }
})

Add presets

export const Button = component('button', baseStyles, {
  variants: {
    color: {
      gray: css`
        background-color: gainsboro;
      `,
      blue: css`
        background-color: dodgerblue;
      `,
    },
    size: {
      md: css`
        height: 26px;
      `,
      lg: css`
        height: 36px;
      `,
    },
  },
  compound: [
    {
      color: 'blue',
      size: 'lg',
      css: css`
        background-color: purple;
      `,
    },
  ],
  defaults: {
    color: 'gray',
    size: 'md',
  },
  presets: {
    primary: {
      color: "blue",
      css: css` @apply p-4;`
    },
  },
});
  1. Preset applies via preset prop.
  2. Preset can apply just css or just variants
  3. Variants passed as props applied over preset
  4. Compound applied after all variants is calculated

Add property `as` to change tag

const Button = component('div', baseStyles)

<Button as="button" />

Allow to pass custom component and infer props from:

<Button as={MyButton} myProp={1} />

Add support for default props

const Button = styled('button', { data: { enabled: $enabled, theme: $theme } })`
  color: red;
`

What about redefining?

Button({
  data: { enabled: $another }
})

What props should win?

Debug mode

When debug is on:

  • Add name and location to asserts (assertKeyframe, assertVariable, assertSelector)
  • Asserts should show informative errors when used in incorrect way (ex.: keyframe used as a selector)
  • Do not minify CSS (if not forced)

When debug is off:

  • Do not add names (if not forced)
  • Replace asserts with getters without informative errors, that should help end-users to report problem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.