Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ See [example](../example)
- `npm run build` in this package
- `npm run build:components` in the root of this project

### How to use components on projects

#### Styles

1. Install [sass](https://www.npmjs.com/package/sass) and [modern-normalize](https://www.npmjs.com/package/modern-normalize)
2. Copy `/styles` folder to your project
- (Optional) If you want to preserve JS exports and functions install [polished](https://www.npmjs.com/package/polished)
- (Optional) If you want to preserve tests, they are written in [jest](https://www.npmjs.com/package/jest) and you must not mock `index.scss` imports (like with `moduleNameMapper` in jest config)
3. Remove unwanted component styles from `styles/index.scss` and add yours project specific
4. Update configs in `styles/tokens/**/index.scss` according to your project needs
5. Import `styles/index.scss` to your project (like in `_app.tsx` in Next.js)
6. Use styles in your components like in the examples

```scss
@use '../../styles/tokens';

.my-class {
color: tokens.color('primary');
}
```

```jsx
const MyComponent = () => <span className="text-color-primary">text</span>
```

## Principles

### Headless UI components
Expand Down
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"classnames": "^2.3.1",
"downshift": "^6.1.7",
"jest-axe": "^6.0.0",
"modern-normalize": "^1.1.0",
"polished": "^4.1.3",
"preact": "~10.5.14",
"preact-render-to-string": "~5.1.19",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/Bar/styles/config.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ---------------------------------------------
// BAR - CONFIGURATION
// ---------------------------------------------
@use "../../../tokens";
@use "../../../styles/tokens";

$spacing: (
default: tokens.space(),
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/Bar/styles/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ---------------------------------------------

@use "./config";
@use "../../../tokens";
@use "../../../styles/tokens";
@use "../../../styles/utils";

@mixin bar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ---------------------------------------------

@use "sass:map";
@use "../../../tokens";
@use "../../../styles/tokens";
@use "../../../styles/utils";
@use "./../../Icon/styles/config" as icons;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@use "sass:list";
@use "./config";
@use "../../../styles/utils";
@use "../../../tokens";
@use "../../../styles/tokens";

// CONTENTS
// Base
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/Card/styles/config.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use "../../../tokens";
@use "../../../styles/tokens";

$card: (
default: (
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/Card/styles/mixins.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@use "sass:map";
@use "./config";
@use "../../../tokens";
@use "../../../styles/tokens";
@use "../../../styles/utils";

@mixin card($card: config.$card) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// DROPDOWN - CONFIGURATION
// ---------------------------------------------

@use "../../../tokens";
@use "../../../styles/tokens";
@use "../../../styles/utils.scss";

$dropdown-menu-max-height: 300px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use "../../../tokens";
@use "../../../styles/tokens";

.file-uploader {
&__preview-item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// FORMS - LABEL - CONFIGURATION
// ---------------------------------------------

@use "../../../tokens";
@use "../../../styles/tokens";
@use "../../../styles/utils";

$label: (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@use "sass:color";
@use "../../../tokens";
@use "../../../styles/tokens";
@use "../../../styles/utils";

$modal-overlay-z-index: 500;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use "sass:map";
@use "./config";
@use "../../../styles/utils";
@use "../../../tokens";
@use "../../../styles/tokens";

@mixin modal($settings: config.$modal) {
@each $breakpoint, $props in $settings {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/Modal/styles/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use "../../../tokens";
@use "../../../styles/tokens";
@use "./mixins";

.modal {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use "../../../tokens";
@use "../../../styles/tokens";

.pagination {
margin-bottom: tokens.space();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// FORMS - SELECT - CONFIGURATION
// ---------------------------------------------

@use "../../../tokens";
@use "../../../styles/tokens";
@use "../../../styles/utils";

$select: (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@use "./config";
@use "../../../styles/utils";
@use "../../../tokens";
@use "../../../styles/tokens";

// Replace letters
@function str-replace($string, $search, $replace: "") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use "../../../tokens";
@use "../../../styles/tokens";
@use "../../../styles/utils";

:root {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/Table/styles/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use "../../../tokens";
@use "../../../styles/tokens";
@use "../../../styles/utils";

.table {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
spaces,
fonts,
shadows,
} from "./tokens";
} from "./styles/tokens";

import "./styles/utilities.scss";
import "./styles/layout.scss";
Expand Down
7 changes: 4 additions & 3 deletions packages/components/src/styles/globals.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "../tokens/colors/globals";
@import "../tokens/space/globals";
@import "../tokens/font/globals";
// NOTE: tokens create css variables in the :root so make sure you are importing globals only once and preferably here so we don't pollute .css files with multiple variabile definitions
@import "./tokens/colors/globals";
@import "./tokens/space/globals";
@import "./tokens/font/globals";
8 changes: 8 additions & 0 deletions packages/components/src/styles/index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// normalize
@import "modern-normalize/modern-normalize.css";

// globals
@import "./globals";

// component styles
@import "./../components/Bar/styles/style.scss";
@import "./../components/Button/styles/style.scss";
@import "./../components/Card/styles/style.scss";
Expand All @@ -10,5 +16,7 @@
@import "./../components/Select/styles/style.scss";
@import "./../components/Slider/styles/style.scss";
@import "./../components/Table/styles/style.scss";

// utilites and overrides
@import "./utilities.scss";
@import "./layout.scss";
2 changes: 1 addition & 1 deletion packages/components/src/styles/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ---------------------------------------------

@use './utils';
@use '../tokens';
@use './tokens';

// mixin for utilities with layout targeting
@mixin spacing-reset-classes($breakpoint: "") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import React, { useMemo } from "react";

import { Table, Code } from "@lighting-beetle/lighter-styleguide";
import flattenObject from "../utils/flattenObject";
import { SCSSVarsMap } from "../utils/scssVarsToMap";
import flattenObject from "../../utils/flattenObject";
import { SCSSVarsMap } from "../../utils/scssVarsToMap";
import { Column } from "react-table";

type UsageFormatFunc = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { renderSync } from "sass";
import { breakpoint } from ".";
import scssTestImporter from "../../utils/scssTestImporter";
import scssTestImporter from "../../../utils/scssTestImporter";

function renderSass(args) {
return renderSync({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use "sass:meta";
@use "sass:map";
@use "sass:list";
@use "./../../styles/utils.scss";
@use "./../../utils.scss";

$breakpoints: (
xs: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TODO: useBreakpoint hook can be probaly useful here

import scssVarsToMap from "../../utils/scssVarsToMap";
import scssVarsToMap from "../../../utils/scssVarsToMap";
import breakpointsFromSCSS from "./export.module.scss";

export const breakpoints = scssVarsToMap(breakpointsFromSCSS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { renderSync } from "sass";
import { color, colorHex } from ".";
import scssTestImporter from "../../utils/scssTestImporter";
import scssTestImporter from "../../../utils/scssTestImporter";

function renderSass(args) {
return renderSync({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scssVarsToMap from "../../utils/scssVarsToMap";
import scssVarsToMap from "../../../utils/scssVarsToMap";
import colorsFromSCSS from "./export.module.scss";

export const colors = scssVarsToMap(colorsFromSCSS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scssVarsToMap from "../../utils/scssVarsToMap";
import scssVarsToMap from "../../../utils/scssVarsToMap";
import fontsSCSSVars from "./export.module.scss";

export const fonts = scssVarsToMap(fontsSCSSVars);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scssVarsToMap from "../../utils/scssVarsToMap";
import scssVarsToMap from "../../../utils/scssVarsToMap";
import shadowsSCSSVars from "./export.module.scss";

export const shadows = scssVarsToMap(shadowsSCSSVars);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use "sass:meta";
@use "sass:map";
@use "sass:list";
@use "./../../styles/utils.scss";
@use "../../utils.scss";

$spaces: (
default: 16px,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { rem } from "../../styles";
import scssVarsToMap from "../../utils/scssVarsToMap";
import { rem } from "../..";
import scssVarsToMap from "../../../utils/scssVarsToMap";
import spacesFromSCSS from "./export.module.scss";

export const spaces = scssVarsToMap(spacesFromSCSS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { renderSync } from "sass";
import { space, spaceValue } from ".";
import scssTestImporter from "../../utils/scssTestImporter";
import scssTestImporter from "../../../utils/scssTestImporter";

function renderSass(args) {
return renderSync({
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/styles/utilities.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@use './utils';
@import "../tokens/font/utilities.scss";
@import "./tokens/font/utilities.scss";

.visually-hidden {
@include utils.visually-hidden();
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/styles/utils.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use "sass:map";
@use "sass:list";
@use "sass:math";
@use "../tokens/font";
@use "./tokens/font";

/// Base on -zf-map-next https://github.com/zurb/foundation-sites/blob/develop/scss/util/_breakpoint.scss
/// Find the next key in a map.
Expand Down
7 changes: 6 additions & 1 deletion packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
"**/*.tsx",
"./react-table-config.d.ts"
],
"exclude": ["node_modules", "dist", "out", "src/tokens/TokensTable.tsx"],
"exclude": [
"node_modules",
"dist",
"out",
"src/styles/tokens/TokensTable.tsx"
],
"compilerOptions": {
"target": "ES2018"
},
Expand Down
1 change: 0 additions & 1 deletion packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"glob": "~7.2.0",
"mdx-bundler": "^8.0.0",
"micromatch": "~4.0.4",
"modern-normalize": "^1.1.0",
"netlify-cms-app": "~2.15.44",
"netlify-cms-widget-mdx": "~0.4.4",
"next": "~12.2.5",
Expand Down
1 change: 0 additions & 1 deletion packages/design-system/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import "modern-normalize/modern-normalize.css";
import "components/styles.scss";

function MyApp({ Component, pageProps }) {
Expand Down
1 change: 0 additions & 1 deletion packages/example-forms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@lighting-beetle/next-lighter-config": "workspace:^",
"components": "workspace:^",
"micromatch": "~4.0.4",
"modern-normalize": "^1.1.0",
"next": "~12.2.5",
"next-transpile-modules": "~9.0.0",
"react": "~17.0.2",
Expand Down
1 change: 0 additions & 1 deletion packages/example-forms/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import "modern-normalize/modern-normalize.css";
import "components/styles.scss";

export default function MyApp({ Component, pageProps }) {
Expand Down
1 change: 0 additions & 1 deletion packages/example-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"dependencies": {
"@lighting-beetle/next-lighter-config": "workspace:^",
"components": "workspace:^",
"modern-normalize": "^1.1.0",
"next": "~12.3.0",
"next-query-params": "^4.0.0",
"next-transpile-modules": "~8.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/example-table/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import { NextAdapter } from "next-query-params";
import { QueryParamProvider } from "use-query-params";
import "modern-normalize/modern-normalize.css";
import "../components/Flats/filters/styles/style.scss";
import "components/styles.scss";

Expand Down
1 change: 0 additions & 1 deletion packages/example/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ export default createConfig({
},
},
plugins: [transpileModules(["components"])],
analyzeBundle: true,
});
1 change: 0 additions & 1 deletion packages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"dependencies": {
"@lighting-beetle/next-lighter-config": "workspace:^",
"components": "workspace:^",
"modern-normalize": "^1.1.0",
"next": "~12.2.5",
"next-transpile-modules": "~9.0.0",
"react": "~17.0.2",
Expand Down
1 change: 0 additions & 1 deletion packages/example/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import "modern-normalize/modern-normalize.css";
import "components/styles.scss";

export default function MyApp({ Component, pageProps }) {
Expand Down
Loading