Skip to content

Commit

Permalink
Merge pull request #529 from buildo/esm2
Browse files Browse the repository at this point in the history
  • Loading branch information
gabro authored Mar 6, 2023
2 parents 1487798 + b00d4c8 commit f6427c5
Show file tree
Hide file tree
Showing 28 changed files with 1,857 additions and 1,566 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const baseConfig = require("./babel.config");
const baseConfig = require("./babel.config.cjs");

module.exports = {
...baseConfig,
Expand Down
9 changes: 0 additions & 9 deletions packages/bento-design-system/jest.config.js

This file was deleted.

8 changes: 8 additions & 0 deletions packages/bento-design-system/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"preset": "ts-jest",
"testEnvironment": "jsdom",
"transform": {
"\\.tsx?$": ["babel-jest", { "configFile": "./babel-jest.config.cjs" }]
},
"setupFilesAfterEnv": ["<rootDir>/test/setupTests.ts"]
}
3 changes: 0 additions & 3 deletions packages/bento-design-system/jsxShim.ts

This file was deleted.

30 changes: 22 additions & 8 deletions packages/bento-design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@
"name": "@buildo/bento-design-system",
"version": "0.16.4",
"description": "The buildo DS",
"main": "lib/index.js",
"main": "lib/index.cjs",
"module": "lib/index.js",
"files": [
"lib"
],
"sideEffects": [
"*.css",
"*.css.ts"
"global.css.ts",
"reset.css.ts",
"defaultTheme.css.ts"
],
"exports": {
".": {
"node": "./lib/index.cjs",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
},
"./index.css": "./lib/index.css",
"./defaultTheme.css": "./lib/defaultTheme.css"
},
"types": "lib/index.d.ts",
"type": "module",
"scripts": {
"build": "tsup --minify --clean",
"prepublishOnly": "pnpm build",
Expand All @@ -20,8 +33,8 @@
"prepublish": "pnpm test && pnpm build",
"test": "jest",
"lint-staged": "lint-staged",
"playroom-start": "playroom start",
"playroom-build": "playroom build",
"playroom-start": "playroom start --config playroom.config.cjs",
"playroom-build": "playroom build --config playroom.config.cjs",
"start": "tsup --watch",
"check-circular-deps": "madge --circular src"
},
Expand Down Expand Up @@ -84,15 +97,15 @@
"@vanilla-extract/recipes": "0.2.5",
"@vanilla-extract/sprinkles": "1.5.1",
"clsx": "^1.2.1",
"deepmerge-ts": "^4.3.0",
"react-cool-dimensions": "^2.0.7",
"react-dropzone": "^14.2.3",
"react-input-mask": "^2.0.4",
"react-keyed-flatten-children": "^1.3.0",
"react-is": "18.2.0",
"react-select": "^5.4.0",
"react-table": "^7.8.0",
"react-use": "^17.4.0",
"recharts": "^2.1.16",
"ts-deepmerge": "^2.0.3",
"ts-pattern": "^3.3.5"
},
"devDependencies": {
Expand All @@ -116,6 +129,7 @@
"@types/react": "18.0.28",
"@types/react-dom": "18.0.11",
"@types/react-input-mask": "2.0.5",
"@types/react-is": "^17.0.3",
"@types/react-table": "7.7.14",
"@vanilla-extract/babel-plugin": "1.1.7",
"@vanilla-extract/esbuild-plugin": "2.1.0",
Expand All @@ -142,7 +156,7 @@
"style-loader": "3.3.1",
"ts-jest": "28.0.8",
"ts-loader": "9.3.1",
"tsup": "6.4.0",
"tsup": "6.6.3",
"typescript": "4.7.4",
"webpack": "5.74.0",
"webpack-cli": "4.10.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const { ProvidePlugin } = require("webpack");
const { ESBuildMinifyPlugin } = require("esbuild-loader");

module.exports = {
components: "../storybook/stories/index.tsx",
typeScriptFiles: ["../storybook/stories/index.tsx"],
components: "./src/index.ts",
outputPath: "./dist/playroom",
title: "Bento 🍱",
widths: [320, 425, 768, 1024, 1440, 2560],
Expand Down Expand Up @@ -34,7 +33,9 @@ module.exports = {
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
exclude: /node_modules/,
exclude: (modulePath) => {
return /node_modules/.test(modulePath) && !modulePath.includes("@fontsource");
},
},
],
},
Expand Down
9 changes: 8 additions & 1 deletion packages/bento-design-system/playroom/FrameComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Box, BentoProvider } from "../../storybook/stories";
import * as React from "react";
import { Box, BentoProvider } from "../src";
import "../src/reset.css";
import "../src/global.css";
import "../src/defaultTheme.css";
import "@fontsource/ibm-plex-sans/400.css";
import "@fontsource/ibm-plex-sans/500.css";
import "@fontsource/ibm-plex-sans/600.css";
import { defaultMessages } from "../../storybook/stories/defaultMessages";

export default function FrameComponent({ theme, children }) {
Expand Down
5 changes: 3 additions & 2 deletions packages/bento-design-system/src/BentoConfigContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext, useContext } from "react";
import * as defaultConfigs from "./util/defaultConfigs";
import type { BentoConfig, PartialBentoConfig } from "./BentoConfig";
import merge from "ts-deepmerge";
import { deepmerge } from "deepmerge-ts";
import { Children } from "./util/Children";

const BentoConfigContext = createContext<BentoConfig>(defaultConfigs);
Expand All @@ -22,8 +22,9 @@ export function BentoConfigProvider({
// So we retrieve the parent config via useBentoConfig(), which will default to the default config
// in case this is the top level provider.
const parentConfig = useBentoConfig();

return (
<BentoConfigContext.Provider value={merge(parentConfig, config)}>
<BentoConfigContext.Provider value={deepmerge(parentConfig, config) as BentoConfig}>
{children}
</BentoConfigContext.Provider>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/bento-design-system/src/Box/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { extractAtomsFromProps } from "@dessert-box/core";
import * as resetStyles from "../reset.css";
import { forwardRef, createElement } from "react";
import clsx, { ClassValue } from "clsx";
import { ClassValue, clsx } from "clsx";
import { useSprinkles } from "../SprinklesContext";
import { SprinklesFn } from "../util/ConfigurableTypes";

Expand Down
7 changes: 3 additions & 4 deletions packages/bento-design-system/src/DateField/DateField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useField } from "@react-aria/label";
import { Input } from "./Input";
import { IconMinus } from "../Icons";
import { dateFieldRecipe } from "./DateField.css";
import clsx from "clsx";
import { LocalizedString } from "../util/LocalizedString";
import { useBentoConfig } from "../BentoConfigContext";
import { getReadOnlyBackgroundStyle } from "../Field/utils";
Expand Down Expand Up @@ -159,7 +158,7 @@ export function DateField(props: Props) {
paddingX={inputConfig.paddingX}
paddingY={inputConfig.paddingY}
background={inputConfig.background.default}
className={clsx(
className={[
inputRecipe({ validation: validationState || "notSet" }),
bodyRecipe({
color: props.disabled ? "disabled" : "primary",
Expand All @@ -169,8 +168,8 @@ export function DateField(props: Props) {
dateFieldRecipe({ validation: validationState || "notSet", isFocused }),
{
readOnly: props.readOnly,
}
)}
},
]}
style={getReadOnlyBackgroundStyle(inputConfig)}
disabled={props.disabled}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/bento-design-system/src/Layout/Columns.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactChild, ReactElement } from "react";
import flattenChildren from "react-keyed-flatten-children";
import { flattenChildren } from "../util/flattenChildren";
import { BoxProps, Box } from "../Box/Box";
import { ResponsiveSpace } from "../internal";
import { normalizeResponsiveValue, OptionalResponsiveValue } from "../internal/sprinkles.css";
Expand Down
2 changes: 1 addition & 1 deletion packages/bento-design-system/src/Layout/Inline.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import flattenChildren from "react-keyed-flatten-children";
import { flattenChildren } from "../util/flattenChildren";
import { Box, AsProp } from "../Box/Box";
import { ResponsiveSpace } from "../internal";
import { Children } from "../util/Children";
Expand Down
2 changes: 1 addition & 1 deletion packages/bento-design-system/src/Layout/Stack.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fragment } from "react";
import flattenChildren from "react-keyed-flatten-children";
import { flattenChildren } from "../util/flattenChildren";
import { Divider } from "../Divider/Divider";
import { ResponsiveAlign, alignToFlexAlign } from "../util/align";
import { childKey } from "../util/childKey";
Expand Down
2 changes: 1 addition & 1 deletion packages/bento-design-system/src/Layout/Tiles.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import flattenChildren from "react-keyed-flatten-children";
import { flattenChildren } from "../util/flattenChildren";
import { Children } from "..";
import { mobileColumns, tabletColumns, desktopColumns, wideColumns } from "./Tiles.css";
import { ResponsiveAlignY, alignYToFlexAlign } from "../util/align";
Expand Down
2 changes: 1 addition & 1 deletion packages/bento-design-system/src/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useOverlay, usePreventScroll, useModal } from "@react-aria/overlays";
import { useDialog } from "@react-aria/dialog";
import { FocusScope } from "@react-aria/focus";
import { modalRecipe, underlay, modalBody } from "./Modal.css";
import useKeyPressEvent from "react-use/lib/useKeyPressEvent";
import { useKeyPressEvent } from "react-use";
import { useDefaultMessages } from "../util/useDefaultMessages";
import { IconButton } from "../IconButton/IconButton";
import { createPortal } from "../util/createPortal";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from "..";
import { singleValue, placeholder, menu, control } from "./SelectField.css";
import { bodyRecipe } from "../Typography/Body/Body.css";
import clsx from "clsx";
import { clsx } from "clsx";
import type { SelectOption } from "./SelectField";
import { InternalList } from "../List/InternalList";
import { ListItem } from "../List/ListItem";
Expand Down
34 changes: 34 additions & 0 deletions packages/bento-design-system/src/util/flattenChildren.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// NOTE(gabro): Adapted from react-keyed-flatten-children, due to lack of ESM build
// Released under the MIT license (https://github.com/grrowl/react-keyed-flatten-children/blob/master/LICENSE)

/* Returns React children into an array, flattening fragments. */
import { ReactNode, ReactElement, Children, isValidElement, cloneElement } from "react";
import { isFragment } from "react-is";

type ReactChild = ReactElement | string | number;

export function flattenChildren(
children: ReactNode,
depth: number = 0,
keys: (string | number)[] = []
): ReactChild[] {
return Children.toArray(children).reduce((acc: ReactChild[], node, nodeIndex) => {
if (isFragment(node)) {
acc.push.apply(
acc,
flattenChildren(node.props.children, depth + 1, keys.concat(node.key || nodeIndex))
);
} else {
if (isValidElement(node)) {
acc.push(
cloneElement(node, {
key: keys.concat(String(node.key)).join("."),
})
);
} else if (typeof node === "string" || typeof node === "number") {
acc.push(node);
}
}
return acc;
}, []);
}
2 changes: 1 addition & 1 deletion packages/bento-design-system/src/util/withBentoConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function withBentoConfig<Props>(
return (props: Props) => {
return (
<BentoConfigProvider value={config}>
<Component {...props} />{" "}
<Component {...props} />
</BentoConfigProvider>
);
};
Expand Down
4 changes: 2 additions & 2 deletions packages/bento-design-system/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { vanillaExtractPlugin } from "@vanilla-extract/esbuild-plugin";

export default defineConfig({
entry: ["src/index.ts", "src/defaultTheme.ts"],
sourcemap: true,
outDir: "lib",
format: ["esm", "cjs"],
esbuildPlugins: [vanillaExtractPlugin()],
dts: true,
// See https://esbuild.github.io/content-types/#auto-import-for-jsx
inject: ["./jsxShim.ts"],
noExternal: ["@fontsource"],
});
4 changes: 2 additions & 2 deletions packages/storybook/stories/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "@buildo/bento-design-system/lib/index.css";
import "@buildo/bento-design-system/lib/defaultTheme.css";
import "@buildo/bento-design-system/index.css";
import "@buildo/bento-design-system/defaultTheme.css";
import "./theme.css";
import {
createBentoProvider,
Expand Down
4 changes: 2 additions & 2 deletions packages/website/docs/02-Getting Started/01-quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Add the Bento package to your project:
Here's how an hello world looks like:

```ts
import "@buildo/bento-design-system/lib/index.css";
import "@buildo/bento-design-system/lib/defaultTheme.css";
import "@buildo/bento-design-system/index.css";
import "@buildo/bento-design-system/defaultTheme.css";
import { BentoProvider, Title } from "@buildo/bento-design-system";
import { defaultMessages } from "./defaultMessages";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default defineConfig({
// Include here the css files coming from external dependencies, which we
// recommend to bundle in your design system package.
noExternal: [
"@buildo/bento-design-system/lib/index.css",
"@buildo/bento-design-system/index.css",
// e.g. here's how to include fonts from Fontsource, a popular library for self-hosting fonts
// "@fontsource",
Expand Down
4 changes: 2 additions & 2 deletions packages/website/docs/03-Customization/01-theming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ This option is available but not recommended, as it's easy to forget or misspell
You can either import the default theme and then override some of the default values using an additional stylesheet, or completely replace `defaultTheme.css` with your own stylesheet defining a value for each of the Bento variables.

```ts title="my-project/design-system/src/index.tsx"
import "@buildo/bento-design-system/lib/index.css";
import "@buildo/bento-design-system/index.css";
import "./theme.css";
```

```css title="my-project/design-system/src/theme.css"
/* Import this file if you want to start from the defaultTheme and only override some variables */
@import "@buildo/bento-design-system/lib/defaultTheme.css";
@import "@buildo/bento-design-system/defaultTheme.css";

:root {
/* change the brand primary color */
Expand Down
3 changes: 1 addition & 2 deletions packages/website/src/components/HomepageFeatures.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import clsx from "clsx";
import styles from "./HomepageFeatures.module.css";

type FeatureItem = {
Expand Down Expand Up @@ -44,7 +43,7 @@ const FeatureList: FeatureItem[] = [

function Feature({ title, image, description }: FeatureItem) {
return (
<div className={clsx("col col--4")}>
<div className={"col col--4"}>
<div className="text--center padding-vert--md">
<img className={styles.featureSvg} alt={title} src={image} />
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/website/src/css/custom.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import "@buildo/bento-design-system/lib/index.css";
@import "@buildo/bento-design-system/lib/defaultTheme.css";
@import "@buildo/bento-design-system/index.css";
@import "@buildo/bento-design-system/defaultTheme.css";

/**
* Any CSS included here will be global. The classic template
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import clsx from "clsx";
import { clsx } from "clsx";
import Layout from "@theme/Layout";
import Link from "@docusaurus/Link";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
Expand Down
Loading

2 comments on commit f6427c5

@vercel
Copy link

@vercel vercel bot commented on f6427c5 Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on f6427c5 Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.