2.4.5 • Published 4 years ago

@team-griffin/stylr v2.4.5

Weekly downloads
23
License
UNLICENCED
Repository
github
Last release
4 years ago

@ux/stylr

useStyles

(
  stylesheet: {
    [modifier: string]: {
      [namespace: string]: {
        [cssProperty: string]: string | number
      }
    }
  },
  modifiers: object | object[]
) => {
  styles: object
}
  • async style loading
  • memoized so we do as few recalculations as possible
  • runtime vendor prefixing (only adds prefixes needed by the current browser)

Usage

// default
const { styles } = useStyles({
  default: {
    root: {
      color: '#000'
    }
  }
});
// modifiers
const { styles } = useStyles({
  default: {
    root: {
      color: '#000'
    }
  },
  invert: {
    root: {
      color: '#FFF'
    }
  }
}, {
  invert: true
})
// key-value modifiers
const { styles } = useStyles({
  default: {
    root: {
      color: '#CCC'
    }
  },
  'theme.light': {
    root: {
      color: '#000'
    }
  },
  'theme.dark': {
    root: {
      color: '#FFF'
    }
  }
}, {
  theme: props.theme
})
// async modifiers
const { styles } = useStyles({
  default: {
    root: {
      color: '#CCC'
    }
  },
  'theme.light': () => import('./light'),
  'theme.dark': () => import('./dark')
}, {
  theme: props.theme
});

caveats

  • due to memoization techniques, any props used by your stylesheet should be passed in as modifiers, otherwise it will not know to recompute the styles when they change

withInteraction

(alias withHover)

(WrappedComponent) => Component

usage

const Interactive = withInteraction((props) => {
  return (
    <span>
      {props.hover ? 'Hovering' : ''}
      {props.focus ? 'Focused' : ''}
      {props.active ? 'Active' : ''}
      {/* when you want the same style for hover and focus */}
      {props.hocus ? 'Hocus' : ''}
    </span>
  );
});

removeInteraction

A hook which omits the props from withInteraction. Use when you want the interaction props for the stylesheet but then to exclude from the actual component; where you use in a component that spreads props you may get Received "false" for a non-boolean attribute console warnings if you don't do this.

2.4.5

4 years ago

2.4.3

4 years ago

2.4.4

4 years ago

2.4.2

4 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago