All Projects → jxnblk → Axs

jxnblk / Axs

Licence: mit
Stupid simple style components for React

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Axs

glitz
Lightweight CSS-in-JS library with high performance written in TypeScript
Stars: ✭ 42 (-80.37%)
Mutual labels:  style, css-in-js
tsstyled
A small, fast, and simple CSS-in-JS solution for React.
Stars: ✭ 52 (-75.7%)
Mutual labels:  style, css-in-js
css-render
Generating CSS using JS with considerable flexibility and extensibility, at both server side and client side.
Stars: ✭ 137 (-35.98%)
Mutual labels:  style, css-in-js
Ui Box
Blazing Fast React UI Primitive
Stars: ✭ 847 (+295.79%)
Mutual labels:  component, css-in-js
Nano Style
React functional CSS-in-JS
Stars: ✭ 85 (-60.28%)
Mutual labels:  style, css-in-js
Styled Typography
Typograpy components for react and styled-components
Stars: ✭ 113 (-47.2%)
Mutual labels:  component, css-in-js
Glamorous Primitives
💄 style primitive React interfaces with glamorous
Stars: ✭ 91 (-57.48%)
Mutual labels:  style, css-in-js
Expo Dark Mode Switch
A beautiful React dark mode switch component for iOS, Android, and Web
Stars: ✭ 137 (-35.98%)
Mutual labels:  style, css-in-js
Babel Plugin React Intl Auto
i18n for the component age. Auto management react-intl ID.
Stars: ✭ 203 (-5.14%)
Mutual labels:  component
Componentcornerstone
🐜🐜 一种全新的android组件化方案,无需下沉公用代码,无需采用路由等硬编码方式分发sdk,独立维护组件暴露的SDK/IMPL,打破官方模块循环且支持组件间互相调用SDK,支持集成组件调试/组件独立运行。A brand new android componentization solution, no need to sink public code, no need to use hard coding to distribute sdk, independent maintenance component exposed SDK / IMPL, break the official module loop and support the call between components The SDK supports integrated component debugging/components to run independently.
Stars: ✭ 207 (-3.27%)
Mutual labels:  component
Komponents Deprecated
📦 React-inspired UIKit Components - ⚠️ Deprecated
Stars: ✭ 202 (-5.61%)
Mutual labels:  component
Navigation Stack
NavigationStack is a stack-modeled UI navigation controller. Swift UI library made by @Ramotion
Stars: ✭ 2,289 (+969.63%)
Mutual labels:  component
React Reorder
Drag & drop, touch enabled, reorderable / sortable list, React component
Stars: ✭ 209 (-2.34%)
Mutual labels:  component
Rdvcalendarview
Highly customizable calendarView and calendarViewController for iOS
Stars: ✭ 203 (-5.14%)
Mutual labels:  component
React Native Typing Animation
💬 A typing animation for your React Native chat app based on simple trigonometry to create better loaders.
Stars: ✭ 211 (-1.4%)
Mutual labels:  component
Nano Component
Fast & simple React component styles in under 1kb
Stars: ✭ 202 (-5.61%)
Mutual labels:  css-in-js
Vue Upload Component
Vue.js file upload component, Multi-file upload, Upload directory, Drag upload, Drag the directory, Upload multiple files at the same time, html4 (IE 9), `PUT` method, Customize the filter
Stars: ✭ 2,422 (+1031.78%)
Mutual labels:  component
React Intl Tel Input
Rewrite International Telephone Input in React.js. (Looking for maintainers, and PRs & contributors are also welcomed!)
Stars: ✭ 212 (-0.93%)
Mutual labels:  component
Browser Kit
The BrowserKit component simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically.
Stars: ✭ 2,563 (+1097.66%)
Mutual labels:  component
React Native Immutable List View
📜 Drop-in replacement for ListView, FlatList, and VirtualizedList.
Stars: ✭ 206 (-3.74%)
Mutual labels:  component

Axs

Stupid simple style components for React

If you know React and you know CSS, you already know how to use this.

Build Status

npm i axs
const Heading = props =>
  <Base.h2
    {...props}
    css={`
      color: tomato;
    `}
  />

A hand axe is a prehistoric stone tool... the longest-used tool in human history.

Features

  • Minimal API surface area
  • One component, three props
  • React component-based API
  • Server side rendering with no additional setup
  • No custom Babel plugins or additional configuration needed
  • Works in iframes
  • 0.7 kb in under 100 LOC

Usage

Basic

Create components by wrapping the Base component and passing props and a css prop to add style.

const Heading = props =>
  <Base
    {...props}
    css={`
      color: tomato;
    `}
  />

CSS syntax

The css prop uses stylis for a CSS-like syntax that allows pseudo-classes, media queries, animations, and nested selectors to be defined inline. See the stylis docs for more info.

const Heading = props =>
  <Base
    {...props}
    css={`
      color: tomato;
      &:hover {
        color: black;
      }
    `}
  />

HTML elements

To change the underlying HTML element, pass a tag name to the is prop.

const Heading = props =>
  <Base
    is='h1'
    {...props}
    css={`
      color: tomato;
    `}
  />

Alternatively, the Base component is decorated with keys for all valid HTML elements, which map to the is prop.

const Heading = props =>
  <Base.h1
    {...props}
    css={`
      color: tomato;
    `}
  />

When using the component, the underlying element can be changed on a per-instance basis using the is prop. This is especially helpful for ensuring the use of correct HTML semantics, while keeping the component styles decoupled.

<Heading is='h2'>
  Hello
</Heading>

Dynamic styles

Styles can be set dynamically based on props.

const Heading = props =>
  <Base.h2
    {...props}
    css={`
      color: ${props.color};
    `}
  />

Using the component above with a custom color passed as a prop would look like this:

<Heading color='tomato'>
  Hello
</Heading>

Note: unlike other libraries like styled-components, the css prop takes a string, not a tagged template literal, so passing functions into the css prop will do nothing.

Removing style props

To remove props used for styling from the underlying HTML element, use destructuring to pick out the props used for styling.

const Heading = ({ color, ...props }) =>
  <Base.h2
    {...props}
    css={`
      color: ${color};
    `}
  />

Styling other components

To style other components, pass the component to the is prop.

const Link = props =>
  <Base
    is={ReactRouter.Link}
    {...props}
    css={`
      color: #07c;
    `}
  />

Extending components

To make an Axs component extensible, pass the css prop argument to the Base component's css prop after the base styles.

const Heading = ({ css, ...props }) =>
  <Base.h2
    {...props}
    css={`
      font-size: 32px;
      ${css}
    `}
  />

To make an extension from the base Heading component, pass it to the is prop.

const BigHeading = props =>
  <Base
    {...props}
    is={Heading}
    css={`
      font-size: 64px;
    `}
  />

Server side rendering

Server side rendering works without the need for any additional setup. This is because CSS rulesets are created within the Base component, which then renders an inline <style> element with the component's CSS.

To render in Node.js, be sure to use CommonJS module syntax or transpile ES modules to CommonJS syntax with a tool like Babel.

const React = require('react')
const { renderToString } = require('react-dom')
const Base = require('axs')

const html = renderToString(
  React.createElement(Base, {
    css: `
      color: tomato;
    `
  }, 'Hello')
)

Pseudo-classes

Since Axs uses stylis to parse strings to valid CSS, pseudo-classes can be added to components with a syntax like the following. The & refers to the component's generated className.

const Link = props =>
  <Base.a
    {...props}
    css={`
      color: #07c;
      text-decoration: none;
      &:hover {
        text-decoration: underline;
      }
    `}
  />

Media queries

Media queries can also be handled inline with stylis syntax.

const Heading = props =>
  <Base.h2
    {...props}
    css={`
      font-size: 32px;
      @media screen and (min-width: 40em) {
        font-size: 48px;
      }
    `}
  />

Animation

CSS animations can also be handled with stylis syntax.

const Heading = props =>
  <Base.h2
    {...props}
    css={`
      font-size: 32px;
      animation-name: pop;
      animation-timing-function: ease-in;
      animation-duration: .2s;

      @keyframes pop {
        0% { transform: scale(.75); }
        50% { transform: scale(1.125); }
        100% { transform: scale(1); }
      }
    `}
  />

Theming

Theming can be added to any Axs component using the theming library.

import React from 'react'
import Base from 'axs'
import { withTheme, ThemeProvider } from 'theming'
import theme from './theme'

const Heading = withTheme(({ color, theme, ...props }) =>
  <Base.h2
    {...props}
    css={`
      color: ${theme.blue};
    `}
  />
)

const App = props => (
  <ThemeProvider theme={theme}>
    <Heading>
      Hello
    </Heading>
  </ThemeProvider>
)

API

Base

The Base component is a primitive React component that takes CSS as a prop, generates a unique className, and renders an inline style element along with the component. The css prop takes a string in a CSS-like syntax and uses stylis to create valid CSS rules. By default the Base component renders an HTML <div> element. To change the underlying HTML element, pass a tag to the is prop or use one of the keyed Base components.

<Base
  is='h2'
  css='color:tomato;'
/>
// using a Base component key
<Base.h2
  css='color:tomato;'
/>
Prop Type Description
css String stylis compatible CSS string to apply to the component
is String or Component sets the underlying HTML tag or React component to style
innerRef Function callback to get the component's React ref

Motivation

React provides a powerful, functional API for rendering HTML with JavaScript. Creating styles for HTML can follow a similar pattern. By building on top of the React API, Axs is meant to make styling components effortless and require as little new syntax as possible. While other CSS-in-JS libraries add custom factory functions, methods, and additional utilities, Axs relies solely on React components and props for its API. The hope is that this makes Axs quicker to learn, easier to use, and more interoperable with the rest of the React ecosystem.

Axs also uses React to render inline style tags rather than adding custom DOM-related code, which makes using the library for server-side rendering work in the same way other React components do. This also means components can be rendered to other documents, such as in iframes, without the need for custom APIs or additional functionality.

Related

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].