Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Playroom integration #4576

Merged
merged 9 commits into from
Jan 22, 2025
Merged
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
6 changes: 6 additions & 0 deletions .github/contribution/component-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ All components should have stories that display their different variations and b
Stories should be written in the file `Component.stories.tsx`.
For more information about using Storybook check the [official documentation](https://storybook.js.org/basics/guide-react/).

## Playroom

For the vast majority of the components, it is valuable to have at least one snippet in the Playroom.
This allows users to quickly access the component in Playroom and craft with it.
The snippet should be written in the file `playroom/snippets` folder, in the most adequate file (if needed, a new file can be created).

## Testing

All components should have unit tests and visual tests. We use [Jest](https://jestjs.io/) for unit testing and their tests should be written in the file `__tests__/index.test.tsx`.
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
yarn tokens build
yarn tailwind-preset build
yarn components build
yarn components build:playroom
yarn components build:storybook

- name: Dry run
if: ${{ github.event.inputs.dryrun == 'true' }}
Expand Down Expand Up @@ -72,3 +74,13 @@ jobs:
yarn docs changelog
git add docs/src/data/log.md && git commit -m "docs: update changelog" && git push
yarn zx scripts/post-changelog.mjs

- name: Get tag version
run: |
git fetch --tags --quiet
echo "VERSION_TAG=$(git tag --list '@kiwicom/orbit-components@*' --sort=creatordate | sed '$!d' | sed -n '$ s|.*@||; s/\./-/gp')" >> $GITHUB_ENV

- name: Get Storybook domain
run: |
echo "DOMAIN=https://kiwicom-orbit-v${VERSION_TAG}.surge.sh" >> $GITHUB_ENV
yarn components deploy:surge ${DOMAIN} --token ${{ secrets.SURGE_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ jobs:
- name: Build tailwind
run: yarn tailwind-preset build

- name: Build Orbit components
run: yarn components build

- name: Build Playroom
run: yarn components build:playroom

- name: Build Storybook
run: yarn components build:storybook

Expand All @@ -46,6 +52,10 @@ jobs:
if: github.ref != 'refs/heads/master'
run: echo "DOMAIN=https://kiwicom-orbit-${BRANCH_URL}.surge.sh" >> $GITHUB_ENV

- name: Get Playroom DOMAIN
if: github.ref != 'refs/heads/master'
run: echo "DOMAIN_PLAYROOM=${DOMAIN}/playroom" >> $GITHUB_ENV

- name: Deploy to staging
if: github.ref != 'refs/heads/master'
run: yarn components deploy:surge ${DOMAIN} --token ${{ secrets.SURGE_TOKEN }}
Expand All @@ -55,7 +65,7 @@ jobs:
uses: actions/github-script@v6
with:
script: |
const commentBody = `Storybook staging is available at ${process.env.DOMAIN}`;
const commentBody = `Storybook staging is available at ${process.env.DOMAIN}\n\nPlayroom staging is available at ${process.env.DOMAIN_PLAYROOM}`;

const commentsList = await github.rest.issues.listComments({
issue_number: context.issue.number,
Expand Down
14 changes: 12 additions & 2 deletions docs/src/components/FancyLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import {
SiStorybook as Storybook,
SiReact as ReactJs,
} from "@icons-pack/react-simple-icons";
import { ColorPicker, Download, FlightDirect, Google, Tips } from "@kiwicom/orbit-components/icons";
import {
ColorPicker,
Download,
FlightDirect,
Google,
Tips,
Code,
} from "@kiwicom/orbit-components/icons";
import { Tile } from "@kiwicom/orbit-components";

import useIsUrlExternal from "../hooks/useIsUrlExternal";
Expand All @@ -19,7 +26,8 @@ type IconNames =
| "google"
| "lightbulb"
| "react"
| "storybook";
| "storybook"
| "playroom";

interface Props {
download?: boolean;
Expand Down Expand Up @@ -54,6 +62,8 @@ const FancyLink = ({ download, href, icon, title }: Props) => {
return <ReactJs />;
case "storybook":
return <Storybook />;
case "playroom":
return <Code />;
case "lightbulb":
return <Tips />;
default:
Expand Down
4 changes: 4 additions & 0 deletions docs/src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ export default function Footer() {
<Dot />
<StyledFooterLink to="https://kiwicom.github.io/orbit/">Storybook</StyledFooterLink>
<Dot />
<StyledFooterLink to="https://kiwicom.github.io/orbit/playroom">
Playroom
</StyledFooterLink>
<Dot />
<StyledFooterLink to="/changelog/">Changelog</StyledFooterLink>
<Dot />
<StyledFooterLink to="/themer/">Themer</StyledFooterLink>
Expand Down
7 changes: 4 additions & 3 deletions docs/src/components/Navbar/Links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ReadArt from "../../images/streamline-light/read-art.svg";
import IrisScanIcon from "../../images/streamline-light/iris-scan.svg";
import ScriptIcon from "../../images/streamline-light/script.svg";

type Link = "Components" | "Guides" | "Tokens" | "Accessibility" | "Foundation" | "Playground";
Copy link
Collaborator

@mvidalgarcia mvidalgarcia Jan 22, 2025

Choose a reason for hiding this comment

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

Will we remove the playground logic? If so, will it be part of a different task?

In case we want to create a ticket.

type Link = "Components" | "Guides" | "Tokens" | "Accessibility" | "Foundation" | "Playroom";

interface Props {
links?: Link[];
Expand All @@ -31,7 +31,7 @@ const LinkIcon = ({ name }: { name?: string }) => {
return <ColorBrushIcon {...iconStyles} />;
case "Accessibility":
return <IrisScanIcon {...iconStyles} />;
case "Playground":
case "Playroom":
return <Code size="medium" />;
default:
return <ScriptIcon {...iconStyles} />;
Expand Down Expand Up @@ -59,6 +59,7 @@ const getLinkPath = (link: Link) => {
if (link === "Tokens") return "/foundation/design-tokens/";
if (link === "Guides") return "/development/guides/";
if (link === "Accessibility") return "/foundation/accessibility/";
if (link === "Playroom") return "https://kiwicom.github.io/orbit/playroom";

return link.toLowerCase();
};
Expand All @@ -82,7 +83,7 @@ const LinkList = ({ isDesktop, links }: { isDesktop?: boolean; links: Props["lin
);

const Links = ({
links = ["Foundation", "Components", "Tokens", "Guides", "Accessibility", "Playground"],
links = ["Foundation", "Components", "Tokens", "Guides", "Accessibility", "Playroom"],
}: Props) => {
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ See [more info about the Orbit provider](/utilities/orbit-provider/).

For a live preview, check out our [Storybook](https://kiwicom.github.io/orbit/) or [orbit.kiwi](https://orbit.kiwi).

You can also try `orbit-components` directly on our [Playground](https://orbit.kiwi/playground/).
You can also try `orbit-components` directly on our [Playroom](https://kiwicom.github.io/orbit/playroom/).

## Typescript

Expand Down
12 changes: 9 additions & 3 deletions docs/src/documentation/01-getting-started/03-github.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ The Orbit Design Tokens package stores all visual UI attributes.
Orbit Storybook provides a preview of all React components,
together with the possibility to play with different variations and settings.

<FancyLink title="Orbit Storybook" href="https://kiwicom.github.io/orbit/" icon="storybook" />

## Playroom

Playroom is a tool that allows you to play with components in a live environment.

<FancyLink
title="Orbit Storybook Playground"
href="https://kiwicom.github.io/orbit/"
icon="storybook"
title="Orbit Playroom"
href="https://kiwicom.github.io/orbit/playroom/"
icon="playroom"
/>

## Orbit Themer
Expand Down
1 change: 1 addition & 0 deletions packages/orbit-components/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.out
.cache
.DS_STORE
.playroom
src/data/airportIllustrations.json
src/data/illustrations.json
src/data/icons.json
Expand Down
9 changes: 7 additions & 2 deletions packages/orbit-components/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ function getAbsolutePath(value: string): string {
}

const config: StorybookConfig = {
staticDirs: [path.resolve(__dirname, "../static")],
stories: ["../src/**/*.stories.*"],
staticDirs: [path.resolve(__dirname, "../static"), path.resolve(__dirname, "../.playroom")],
stories: ["../src/**/*.@(mdx|stories.*)"],
framework: getAbsolutePath("@storybook/react-webpack5"),

addons: [
Expand Down Expand Up @@ -44,6 +44,7 @@ const config: StorybookConfig = {
},
},
],

webpackFinal(cfg) {
if (cfg) {
// resolve to .js rather than .mjs to avoid webpack failing because of ambiguous imports
Expand All @@ -60,6 +61,10 @@ const config: StorybookConfig = {
}
return undefined;
},

typescript: {
reactDocgen: "react-docgen-typescript",
},
};

export default config;
2 changes: 1 addition & 1 deletion packages/orbit-components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ or do so with [Yarn](https://yarnpkg.com/):

For a live preview, check out our [Storybook](https://kiwicom.github.io/orbit/) or [orbit.kiwi](https://orbit.kiwi).

You can also try `orbit-components` directly on our [Playground](https://orbit.kiwi/playground/).
You can also try `orbit-components` directly on our [Playroom](https://kiwicom.github.io/orbit/playroom/).

## Contributing

Expand Down
25 changes: 14 additions & 11 deletions packages/orbit-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"scripts": {
"storybook": "storybook dev -p 6007 -c .storybook --ci",
"playroom": "playroom start",
"cy:dev": "vite cypress/integration --logLevel silent",
"cy:run": "start-server-and-test cy:dev http-get://localhost:3000 'cypress run'",
"cy:open": "start-server-and-test cy:dev http-get://localhost:3000 'cypress open'",
Expand All @@ -27,6 +28,7 @@
"build:iconsFont": "node --loader ts-node/esm config/createSVGFont.mts",
"build:emailIcons": "yarn build:icons && yarn build:iconsFont && node --loader ts-node/esm config/generateEmailIcons.mts",
"build:storybook": "yarn build:icons && storybook build -c .storybook -o .out",
"build:playroom": "playroom build",
"eslint:check": "eslint . --report-unused-disable-directives",
"test-ct": "playwright test -c playwright-ct.config.ts",
"deploy:storybook": "yarn storybook-to-ghpages -e ./.out",
Expand Down Expand Up @@ -91,17 +93,17 @@
"@nanostores/router": "^0.3.1",
"@playwright/experimental-ct-react": "^1.44.1",
"@size-limit/webpack-why": "^11.1.4",
"@storybook/addon-a11y": "^8.2.4",
"@storybook/addon-controls": "^8.2.4",
"@storybook/addon-essentials": "^8.2.4",
"@storybook/addon-styling-webpack": "^1.0.0",
"@storybook/blocks": "^8.2.4",
"@storybook/manager-api": "^8.2.4",
"@storybook/preview-api": "^8.2.4",
"@storybook/react": "^8.2.4",
"@storybook/addon-a11y": "^8.4.7",
"@storybook/addon-controls": "^8.4.7",
"@storybook/addon-essentials": "^8.4.7",
"@storybook/addon-styling-webpack": "^1.0.1",
"@storybook/blocks": "^8.4.7",
"@storybook/manager-api": "^8.4.7",
"@storybook/preview-api": "^8.4.7",
"@storybook/react": "^8.4.7",
"@storybook/react-webpack5": "^8.4.7",
"@storybook/storybook-deployer": "^2.8.16",
"@storybook/theming": "^8.2.1",
"@storybook/theming": "^8.4.7",
"@svgr/core": "^6.3.1",
"@svgr/plugin-jsx": "^6.3.1",
"@svgr/plugin-prettier": "^6.3.1",
Expand All @@ -116,7 +118,7 @@
"babel-plugin-require-context-hook": "^1.0.0",
"css-loader": "^7.1.2",
"cypress": "^13.2.0",
"eslint-plugin-storybook": "^0.9.0",
"eslint-plugin-storybook": "^0.11.2",
"fs-extra": "^11.2.0",
"jscodeshift": "^0.13.1",
"jsdom": "^20.0.3",
Expand All @@ -125,14 +127,15 @@
"onecolor": "^4.1.0",
"ora": "^6.1.0",
"pixelmatch": "^5.3.0",
"playroom": "^0.39.1",
"pngjs": "^7.0.0",
"postcss-loader": "8.1.1",
"prism-react-renderer": "^2.3.1",
"react-element-to-jsx-string": "^14.3.2",
"react-window": "^1.8.10",
"sharp": "^0.32.6",
"start-server-and-test": "^1.13.1",
"storybook": "^8.2.4",
"storybook": "^8.4.7",
"storybook-addon-pseudo-states": "^4.0.2",
"style-loader": "^4.0.0",
"surge": "^0.23.0",
Expand Down
88 changes: 88 additions & 0 deletions packages/orbit-components/playroom.config.js
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity, do you know if there is any possibility of customizing the Playroom UI a little bit? Adding an orbit header, palette, etc.

Not critical of course.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have never tried, but I recall seeing someone asking about it. I did not read through because I was looking for an answer on something else, though 😅

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const path = require("path");
const { defaultFoundation } = require("@kiwicom/orbit-design-tokens");

module.exports = {
title: "Orbit Playroom",
components: require.resolve("./playroomComponents.tsx"),
outputPath: "./.playroom/playroom",
frameComponent: "./playroom/FrameComponent.tsx",
snippets: "./playroom/snippets/index.ts",
scope: "./playroom/scope.ts",
port: 9000,
openBrowser: false,
widths: Object.values(defaultFoundation.breakpoint),
defaultVisibleWidths: [
defaultFoundation.breakpoint.mediumMobile,
defaultFoundation.breakpoint.desktop,
],
baseUrl: "/playroom/",
webpackConfig: () => ({
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx", ".css"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need .js* extensions?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe playroom is actually checking for the built files, inside lib, so it's js. But I didn't check it back then. I would suggest we come back to this soon with this and other improvements

modules: [
"node_modules",
path.resolve(__dirname),
path.resolve(__dirname, "src"),
path.resolve(__dirname, "lib"),
path.resolve(__dirname, "node_modules"),
path.resolve(__dirname, "../.."),
],
alias: {
"@kiwicom/orbit-components": path.resolve(__dirname),
},
},
module: {
rules: [
{
test: /\.css$/i,
sideEffects: true,
exclude: /node_modules/,
use: [
require.resolve("style-loader"),
require.resolve("css-loader"),
{
loader: require.resolve("postcss-loader"),
options: {
postcssOptions: {
plugins: [require.resolve("tailwindcss"), require.resolve("autoprefixer")],
},
},
},
],
},
{
test: /\.(js|jsx|ts|tsx)$/,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"],
},
},
},
],
},
}),
reactDocgenTypescriptConfig: {
// TODO: Disabling prop intellisense until we can fix the issue with correctly getting the props
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have we created a ticket about this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No. I will create tickets for playroom improvements now

propFilter: () => false,
},
exampleCode: `
<div className="bg-white-normal p-300 h-screen">
<Context>
{() => {
const [hasError, setHasError] = React.useState(false);

return (
<Button
onClick={() => setHasError(!hasError)}
type={hasError ? "critical" : "primary"}
>
{hasError ? "Ups, click again" : "Click Me"}
</Button>
);
}}
</Context>
</div>
`,
};
Loading
Loading