Git Product home page Git Product logo

react-native-styled-system's Introduction


React Native Styled System

NPM downloads NPM version License

Bring styled-system to React Native


React Native Styled System is a React Native implementation of the styled-system package commonly used on the web.

Highlights

  • ⚡️ All styles are allowed to be cached. So it doesn't cause any rerender if result is consistent.
  • ⭐️ Allows arguments such as m, px, py, bg, flex, flexDirection, position to be passed directly to Props according to the grammar of styled-system.
  • 🎨 Users can define the design system by directly defining and delivering themes.
  • ❤️ TypeScript can be fully used through the Type Generation process using CLI.
  • 🚀 Logical or responsive values such as safeAreaTop and sidePadding can be injected into the theme and used as token values.
  • 💬 Text Typography
  • 🎉 Integrate Dark Theme easily.

Why we need styled-system

Let me show this code.

const Sample = () => {
  const theme = useTheme();

  return (
    <View style={{
      backgroundColor: theme.colors.red500,
      borderRadius: theme.radii.lg
    }}>
      <Text style={[theme.typography.h1, { marginTop: theme.spaces[4] }]}>
        React Native
      </Text>
    </View>
  );
};

This is quite verbose.

With Styled System! 👇

const Sample = () => {
  return (
    <Box bg={'red500'} radius={'lg'}>
      <Txt t={'h1'} mt={4}>
        React Native
      </Txt>
    </Box>
  );
};

styled-system is useful for rapid UI development by providing a consistent approach to styling in React applications.

It offers a design system with predefined style props that streamline component styling, ensuring scalability, consistency, and responsive design.

But original styled-system is for CSS not in React Native.

We introduce React Native Styled System 🎉

 

Note

It does not fully support the grammar of styled-system and there are some grammars that are not currently supported, but this is not a technical limitation and will be added as needed.

Styles such as justifySelf that are not yet supported in React Native obviously cannot be added in the future.

Contributing

Feel like contributing? That's awesome! We have a contributing guide to help guide you.

Lincese

MIT

react-native-styled-system's People

Contributors

github-actions[bot] avatar mym0404 avatar zmin9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

odysseyj

react-native-styled-system's Issues

[FR]: example app

Is there an existing issue for this?

  • I have searched the existing issues

Describe the problem

We should create example project for easing of development or contribution.

Describe the solution

I will refer this project's settings

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[FR]: cache result style for performance.

Is there an existing issue for this?

  • I have searched the existing issues

Describe the problem

TITC

Describe the solution

Can object-hash be used?

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[BUG]: priority is not respected if shortcut name and full name are used both.

Is there an existing issue for this?

  • I have searched the existing issues

Version

1.0.3

What happened?

The priorities is not respected if shortcut name and full name are used both.

For example, when fallback contains background and sx prop contains bg, the background is prioritized as a result.

Relevant a package.json.

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[FR]: Add Example Components into documentation

Is there an existing issue for this?

  • I have searched the existing issues

Describe the problem

It would be good if examples such as StyledView and StyledScrollView were organized in the docs.

Describe the solution

TITC

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[FR]: Calculate property based on other properties

Describe the problem

Set a property based on other style property is tricky now.

Describe the solution

Function, yes we need a functional api that receives calculated style and returns transformed properties like hook.

Let me show,

const safeAreaBottom = /* ... */
const isSafeAreaBottomIncludedAtPaddingBottom = /* ... */

const { /* ... */ } = useSx(props, {
  transform: (calculated: ViewStyle) => ({
    bt: isSafeAreaBottomIncludedAtPaddingBottom ?
      ((calculated.paddingBottom ?? 0) + safeAreaBottom) : calculated.paddingBottom
  }),
});

The type of transform argument should be like (ViewStyle | TextStyle) => ViewStyle | TextStyle.

Note

If we support default prop at useSx options too, then it will be very convenient for using the API.

Code of Conduct

  • I agree to follow this project's Code of Conduct

[FR]: Support TextStyle

Is there an existing issue for this?

  • I have searched the existing issues

Describe the problem

We should support TextStyle for Text or EditText also.

Describe the solution

Add styleType options to useSx options and parse TextStyle props too.

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[FR]: Default style property in `useSx` option

Describe the problem

At now, the getStyle function takes SxProps as a parameter for passing additional style properties.

It is handled with lowest priority because it is used for default property sometimes.

We should separate a concern between defining default style properties and passing additional style properties.

Describe the solution

Step 1. Create default(not fixed name) options to useSx hook.

const { /* ... */ } = useSx(props, {
  default: {
    borderWidth: 1,
  },
});

Important

This SxProps should be handled as most lowest priority

Step 2(NEED DISCUSSION). The priority of SxProps as getStyle parameter should be highest one?(lower than style).

I have no idea how this priority should be updated.

Note

We should update this new behaviors in the docs.

Code of Conduct

  • I agree to follow this project's Code of Conduct

[FR]: Docs for Dark Theme

Is there an existing issue for this?

  • I have searched the existing issues

Describe the problem

This library supports dark theme. Because the ThemedDict object is injected at StyledSystemProvider.

The state of whether theme is dark mode is managed outside of this library's context.

Just writing a guide document in docs at advanced section is needed.

Describe the solution

TITC

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

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.