Skip to content

Commit

Permalink
remove css imports from components (#1322)
Browse files Browse the repository at this point in the history
Removed all css imports from every component and created a styles.css file that can be manually imported. Part of css-modules work.
  • Loading branch information
mayank99 authored Jun 6, 2023
1 parent d94cceb commit f4cb394
Show file tree
Hide file tree
Showing 136 changed files with 139 additions and 232 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-owls-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': major
---

All css imports within components have been removed. `@itwin/itwinui-react/styles.css` must now be manually imported at the entrypoint.
5 changes: 5 additions & 0 deletions .changeset/many-actors-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-css': major
---

Removed input-container code from `utils.css` in favor of `input-container.css`.
1 change: 1 addition & 0 deletions apps/storybook/.storybook/StoryWithDecorator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import * as React from 'react';
import { useDarkMode } from 'storybook-dark-mode';
import { ThemeProvider } from '@itwin/itwinui-react';
import '@itwin/itwinui-react/styles.css';

export default function StoryWithDecorator(Story, context) {
const theme = useDarkMode() ? 'dark' : 'light';
Expand Down
50 changes: 32 additions & 18 deletions apps/storybook/src/Overview.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,52 @@ npm install @itwin/itwinui-react
yarn add @itwin/itwinui-react
```

## Usage
---

Import the component you want and start using it!
## Setup

```jsx
import { Button } from '@itwin/itwinui-react';
Wrap your application entrypoint in `ThemeProvider` and import `styles.css`.

const App = () => <Button>Hello!</Button>;
```jsx
import { ThemeProvider } from '@itwin/itwinui-react';
import '@itwin/itwinui-react/styles.css';

export default function App() {
return (
<>
<ThemeProvider>
{/* Your components go here. */}
</ThemeProvider>
</>
);
}
```

Yes, that's really all you need as you can see in this live interactive demo:
ThemeProvider has a `theme` prop which accepts one of the following values:

[![Edit in CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/s/github/iTwin/iTwinUI/tree/main/cra-sandbox?file=/src/App.tsx)
- `light` (default)
- `dark`
- `os` (respects the color scheme of the operating system)
- `inherit`

## Theming
---

By default, all components use the light theme, but we recommend wrapping your root element with `ThemeProvider`. You can pass one of the following values to its `theme` prop:
## Usage

- `light` (default)
- `dark`
- `os` (which respects the color scheme of the operating system)
After setting up ThemeProvider and styles, import the component you want and start using it!

```jsx
import { ThemeProvider } from '@itwin/itwinui-react';
import { Button } from '@itwin/itwinui-react';

const App = () => (
<>
<ThemeProvider theme='dark'>{/* Your components go here. */}</ThemeProvider>
</>
);
const Page = () => <Button>Hello!</Button>;
```

Check out this template for a live interactive demo:

[![Edit in CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/s/github/iTwin/iTwinUI/tree/main/cra-sandbox?file=/src/App.tsx)

---

## FAQ

For a list of frequently asked questions, visit the [wiki](https://github.com/iTwin/iTwinUI/wiki/FAQ).
Expand Down
42 changes: 25 additions & 17 deletions apps/website/src/pages/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,40 @@ npm install @itwin/itwinui-react
yarn add @itwin/itwinui-react
```

## Usage
## Setup

Import the component you want and start using it!
Wrap your application entrypoint in `ThemeProvider` and import `styles.css`.

```jsx
import { Button } from '@itwin/itwinui-react';

const App = () => <Button>Hello!</Button>;
import { ThemeProvider } from '@itwin/itwinui-react';
import '@itwin/itwinui-react/styles.css';

export default function App() {
return (
<>
<ThemeProvider>{/* Your components go here. */}</ThemeProvider>
</>
);
}
```

## Theming

By default, all components use the light theme, but we recommend wrapping your root element with `ThemeProvider`. You can pass one of the following values to its `theme` prop:
ThemeProvider has a `theme` prop which accepts one of the following values:

- `light` (default)
- `dark`
- `os` (which respects the color scheme of the operating system)
- `os` (respects the color scheme of the operating system)
- `inherit`

## Usage

After setting up ThemeProvider and styles, import the component you want and start using it!

```jsx
import { ThemeProvider } from '@itwin/itwinui-react';
import { Button } from '@itwin/itwinui-react';

const App = () => (
<>
<ThemeProvider theme='dark'>
<>{/* Your components go here. */}</>
</ThemeProvider>
</>
);
const Page = () => <Button>Hello!</Button>;
```

Check out this template for a live interactive demo:

[![Edit in CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/s/github/iTwin/iTwinUI/tree/main/cra-sandbox?file=/src/App.tsx)
3 changes: 1 addition & 2 deletions apps/website/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
import '@itwin/itwinui-css/css/all.css';
import '@itwin/itwinui-variables';
import '@itwin/itwinui-react/styles.css';
import Global from './_global.astro';
import Header from '~/components/Header.astro';
import ITwinUILogo from '~/components/iTwinUILogo';
Expand Down
1 change: 1 addition & 0 deletions cra-sandbox/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';
import { IconButton, ThemeProvider } from '@itwin/itwinui-react';
import '@itwin/itwinui-react/styles.css';
import './styles.css';

const rootElement = document.getElementById('root')!;
Expand Down
1 change: 1 addition & 0 deletions packages/itwinui-css/src/all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@forward 'header/header';
@forward 'information-panel/information-panel';
@forward 'input/input';
@forward 'input-container/input-container';
@forward 'keyboard/keyboard';
@forward 'location-marker/location-marker';
@forward 'menu/menu';
Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-css/src/utils/utils.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Bentley Systems, Incorporated. All rights reserved.
// See LICENSE.md in the project root for license terms and full copyright notice.
@forward 'icon';
@forward '../input-container/input-container'; // forwarded here in utils to avoid breaking
@forward 'notification-marker';
@forward 'popover';
@forward 'divider';
Expand Down
50 changes: 28 additions & 22 deletions packages/itwinui-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,49 @@ yarn add @itwin/itwinui-react

---

## Usage
## Setup

Import the component you want and start using it!
Wrap your application entrypoint in `ThemeProvider` and import `styles.css`.

```jsx
import { Button } from '@itwin/itwinui-react';

const App = () => (
<Button>Hello!</Button>
);
import { ThemeProvider } from '@itwin/itwinui-react';
import '@itwin/itwinui-react/styles.css';

export default function App() {
return (
<>
<ThemeProvider>
{/* Your components go here. */}
</ThemeProvider>
</>
);
}
```

Yes, that's really all you need as you can see in this live interactive demo:

[![Edit in CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/s/github/iTwin/iTwinUI/tree/main/cra-sandbox?file=/src/App.tsx)
ThemeProvider has a `theme` prop which accepts one of the following values:
- `light` (default)
- `dark`
- `os` (respects the color scheme of the operating system)
- `inherit`

---

## Theming
## Usage

By default, all components use the light theme, but we recommend wrapping your root element with `ThemeProvider`. You can pass one of the following values to its `theme` prop:
- `light` (default)
- `dark`
- `os` (which respects the color scheme of the operating system)
After setting up ThemeProvider and styles, import the component you want and start using it!

```jsx
import { ThemeProvider } from '@itwin/itwinui-react';
import { Button } from '@itwin/itwinui-react';

const App = () => (
<>
<ThemeProvider theme='dark'>
{/* Your components go here. */}
</ThemeProvider>
</>
const Page = () => (
<Button>Hello!</Button>
);
```

Check out this template for a live interactive demo:

[![Edit in CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/s/github/iTwin/iTwinUI/tree/main/cra-sandbox?file=/src/App.tsx)

---

## FAQ
Expand Down
2 changes: 0 additions & 2 deletions packages/itwinui-react/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ module.exports = {

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
'\\.(css|less|sass|scss)$': '<rootDir>/src/__mocks__/styleMock.js',
'\\.(gif|ttf|eot|svg)$': '<rootDir>/src/__mocks__/fileMock.js',
'^(\\.\\.?\\/.+)\\.jsx?$': '$1', // see https://github.com/kulshekhar/ts-jest/issues/1057
},

Expand Down
7 changes: 3 additions & 4 deletions packages/itwinui-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"default": "./cjs/index.js"
}
},
"./styles.css": "./styles.css",
"./cjs": "./cjs/index.js",
"./esm": "./esm/index.js",
"./cjs/core/utils": "./cjs/core/utils/index.js",
Expand All @@ -26,6 +27,7 @@
"files": [
"cjs",
"esm",
"styles.css",
"CHANGELOG.md",
"LICENSE.md"
],
Expand Down Expand Up @@ -124,8 +126,5 @@
]
},
"prettier": "configs/prettier-config",
"sideEffects": [
"**/*.scss",
"**/*.css"
]
"sideEffects": false
}
5 changes: 0 additions & 5 deletions packages/itwinui-react/src/__mocks__/fileMock.js

This file was deleted.

5 changes: 0 additions & 5 deletions packages/itwinui-react/src/__mocks__/styleMock.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import cx from 'classnames';
import * as React from 'react';
import '@itwin/itwinui-css/css/alert.css';
import { StatusIconMap, SvgCloseSmall, Box } from '../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../utils/index.js';

Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import cx from 'classnames';
import * as React from 'react';
import { Box } from '../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../utils/index.js';
import '@itwin/itwinui-css/css/avatar.css';

export type AvatarStatus = 'online' | 'busy' | 'away' | 'offline';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as React from 'react';
import cx from 'classnames';
import { Box } from '../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../utils/index.js';
import '@itwin/itwinui-css/css/avatar.css';

type AvatarGroupProps = {
/**
Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Backdrop/Backdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as React from 'react';
import cx from 'classnames';
import { Box } from '../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../utils/index.js';
import '@itwin/itwinui-css/css/backdrop.css';

export type BackdropProps = {
/**
Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
AnyString,
PolymorphicForwardRefComponent,
} from '../utils/index.js';
import '@itwin/itwinui-css/css/badge.css';

/**
* Helper function that returns one of the preset badge color values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Box,
} from '../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../utils/index.js';
import '@itwin/itwinui-css/css/breadcrumbs.css';

type BreadcrumbsProps = {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as React from 'react';
import cx from 'classnames';
import { useOverflow, useMergedRefs, Box } from '../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../utils/index.js';
import '@itwin/itwinui-css/css/button.css';

type ButtonGroupProps = {
/**
Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Buttons/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as React from 'react';

import { Box } from '../../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
import '@itwin/itwinui-css/css/button.css';

export type ButtonProps = {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
useMergedRefs,
} from '../../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
import '@itwin/itwinui-css/css/button.css';

export type DropdownButtonProps = {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import * as React from 'react';
import { VisuallyHidden, Popover, Box } from '../../utils/index.js';
import type { ButtonProps } from '../Button/Button.js';
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
import '@itwin/itwinui-css/css/button.css';
import '@itwin/itwinui-css/css/tooltip.css';

export type IconButtonProps = {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { DropdownMenu } from '../../DropdownMenu/index.js';
import type { Placement } from 'tippy.js';
import { Box, SvgCaretDownSmall, SvgCaretUpSmall } from '../../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
import '@itwin/itwinui-css/css/button.css';

export type SplitButtonProps = ButtonProps & {
/**
Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Carousel/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as React from 'react';
import cx from 'classnames';
import { getRandomValue, useMergedRefs, Box } from '../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../utils/index.js';
import '@itwin/itwinui-css/css/carousel.css';
import { CarouselContext } from './CarouselContext.js';
import { CarouselSlider } from './CarouselSlider.js';
import { CarouselSlide } from './CarouselSlide.js';
Expand Down
Loading

0 comments on commit f4cb394

Please sign in to comment.