7.18.1 • Published 5 months ago

@digitalroute/theme v7.18.1

Weekly downloads
-
License
-
Repository
github
Last release
5 months ago

When to use the DR-Theme

  • When styling Ant Design components with styles that should apply to all components and not just specific ones.
  • When we start to repeat ourselfs in the styling of things e.g you specifing the same color for the 2:nd or 3:rd time.
  • When .....

How

Please note, this repository uses semantic release. Please read about it in the Conventional Commits page in Confluence.

  1. Run npm install to install dependencies
  2. Make your changes
  3. Make sure your changes are visible in the storybook (add a new story if necessary) and hasn't broken any of the existing ones: npm run storybook
  4. When you're satisfied with the result, stage your changes using git add and then commit using npm run commit. Add a nice descriptive comment about the changes.
  5. Push to your feature branch and create a PR.

Peer dependencies

Currently this module expects to find peer dependencies for react (^17.0.0) and antd (4.16.3) in your app.

Theme With react-jss

This is an implementation of theming react apps using react-jss. For smooth integration with antd, we have a custom webpack loader which parses the antd's LESS files and extracts all variables into the a theme which is provided in the app for usage when styling components. Hence, any changes of antd's components, and theme variables in general, is accomplished through setting the different LESS variables exposed by antd found in eg. ./src/theme.less.

One of the most important benefits of JSS is that it promotes components to be contained in a single file. This encourages and ensures pain-free future refactorings without also having to deal with external stylesheets. A list of benefits, as well as more useful information can be found att jss' website. The integration with antd also ensures that theming of the existing components is done seamlessly.

Whilst LESS is used in this module due to antd, there is no requirement for any consuming library to use LESS. Preferably, the functionality provided by JSS will be more than enough even for advanced stylerz.

The module exposes two utility functions for consumers to use, shortly explained below. Simple but complete examples can be found in ./stories/index.jsx. To show them live, run npm install && npm run storybook.

Whilst we haven't yet published this to an NPM registry, you can use the module by adding the following dependency:

"@digitalroute/theme": "git+ssh://git@bitbucket.digitalroute.com:7999/daz/dr-theme.git#<tag>"

withTheme(app: Component)

import { withTheme } from '@digitalroute/theme';

class App extends React.Component {
    render() {
        <SomeComponent />
        ...
    }
}
const ThemedApp = withTheme(App);

useStyles

useStyles are not exported by dr-theme, but to provide an example how to use it below, theme is injected by withTheme in the top of the application as shown above.

import { createUseStyles } from "react-jss";

// Styles only need to be a function when theme is used, object otherwise
const styles = (theme) => ({
    yolo: {
        display: 'flex',
        flexDirection: 'column',
        color: theme.primaryColor,
        ...
    },
    ...
});
const useStyles = createUseStyles(styles);

export const SomeComponent = () => {
    const classes = useStyles();

    return <div className={classes.yolo}/>
};

LEGACY (Deprecated in react-jss v10) Creates a higher-order-component (HOC) of your app that sets up and provides the theme. Typically, this is used near the root-component in an application and applied on a single component in the component-tree. Preferred to use only with class component, as useStyles hooks are replacing this.

withStyles(styles: func)

Creates a new function which in turn accepts a component to turn into a styled (HOC) version, through which the defined css-classes defined in styles are provided as a the "classes"-prop:

import { withStyles } from '@digitalroute/theme';
import { WithStylesProps } from '@digitalroute/theme';

const styles = (theme) => ({
    yolo: {
        display: 'flex',
        flexDirection: 'column',
        color: theme.primaryColor,
        ...
    },
    ...
});

interface Props extends WithStylesProps<typeof styles> {}

const SomeComponent = ({ classes }:Props) => (
    <div className={classes.yolo}>
    	...
    </div>
);

export default withStyles(styles)(SomeComponent);

TODOs

We'll eg. be looking into reducing the dist size.

7.18.1

5 months ago

7.18.0

1 year ago

7.17.0

1 year ago

7.16.0

1 year ago

7.14.0

1 year ago

7.15.0

1 year ago

7.13.0

1 year ago

7.8.0

2 years ago

7.9.0

2 years ago

7.12.0

2 years ago

7.12.1

2 years ago

7.10.0

2 years ago

7.11.0

2 years ago

7.4.0

2 years ago

7.7.0

2 years ago

7.6.0

2 years ago

7.5.0

2 years ago

7.3.0

2 years ago

7.2.0

2 years ago

6.1.0

3 years ago

7.0.0

3 years ago

7.1.1

3 years ago

7.1.0

3 years ago

6.0.10

3 years ago

6.0.9

3 years ago

6.0.8

3 years ago

5.4.1

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

6.0.3

3 years ago

6.0.2

3 years ago

6.0.4

3 years ago

6.0.7

3 years ago

6.0.6

3 years ago

5.4.0

3 years ago

5.3.0

3 years ago

5.2.0

3 years ago

5.1.0

3 years ago