From 436e92cd17179d9fe51aa65b20ee2a17c150b08c Mon Sep 17 00:00:00 2001 From: Charles de Dreuille Date: Mon, 30 Dec 2024 15:24:36 +0100 Subject: [PATCH] Improve docs Signed-off-by: Charles de Dreuille --- microsite-canon/components/Chip/Chip.tsx | 7 +- .../Chip/{styles.css => styles.module.css} | 10 +- .../components/PropsTable/PropsTable.tsx | 4 +- .../components/PropsTable/getProps.ts | 43 ------ .../components/PropsTable/index.ts | 1 - microsite-canon/components/Story/index.tsx | 21 +++ .../components/Story/styles.module.css | 7 + microsite-canon/components/Table/Table.tsx | 15 ++- microsite-canon/components/Table/styles.css | 72 ---------- .../components/Table/styles.module.css | 73 ++++++++++ microsite-canon/content/box.mdx | 99 ++++++++++++++ microsite-canon/content/button.mdx | 126 +++++++++++++++++- microsite-canon/mdx-components.tsx | 14 ++ microsite-canon/utils/spaceProps.ts | 41 ++++++ 14 files changed, 403 insertions(+), 130 deletions(-) rename microsite-canon/components/Chip/{styles.css => styles.module.css} (92%) delete mode 100644 microsite-canon/components/PropsTable/getProps.ts create mode 100644 microsite-canon/components/Story/index.tsx create mode 100644 microsite-canon/components/Story/styles.module.css delete mode 100644 microsite-canon/components/Table/styles.css create mode 100644 microsite-canon/components/Table/styles.module.css create mode 100644 microsite-canon/content/box.mdx create mode 100644 microsite-canon/utils/spaceProps.ts diff --git a/microsite-canon/components/Chip/Chip.tsx b/microsite-canon/components/Chip/Chip.tsx index e6e1d1b1c4..d6a74502e0 100644 --- a/microsite-canon/components/Chip/Chip.tsx +++ b/microsite-canon/components/Chip/Chip.tsx @@ -15,6 +15,7 @@ */ import React from 'react'; +import styles from './styles.module.css'; export const Chip = ({ children, @@ -23,5 +24,9 @@ export const Chip = ({ children: React.ReactNode; head?: boolean; }) => { - return {children}; + return ( + + {children} + + ); }; diff --git a/microsite-canon/components/Chip/styles.css b/microsite-canon/components/Chip/styles.module.css similarity index 92% rename from microsite-canon/components/Chip/styles.css rename to microsite-canon/components/Chip/styles.module.css index 95cf7cef34..6955f9b0e8 100644 --- a/microsite-canon/components/Chip/styles.css +++ b/microsite-canon/components/Chip/styles.module.css @@ -25,9 +25,9 @@ margin-right: 4px; background-color: #f0f0f0; color: #5d5d5d; - - &.head { - background-color: #eaf2fd; - color: #2563eb; - } +} + +.head { + background-color: #eaf2fd; + color: #2563eb; } diff --git a/microsite-canon/components/PropsTable/PropsTable.tsx b/microsite-canon/components/PropsTable/PropsTable.tsx index a3dc9e271c..bb9450c9cc 100644 --- a/microsite-canon/components/PropsTable/PropsTable.tsx +++ b/microsite-canon/components/PropsTable/PropsTable.tsx @@ -15,8 +15,8 @@ */ import React from 'react'; -import * as Table from '..'; -import { Chip } from '..'; +import * as Table from '../Table'; +import { Chip } from '../Chip'; // Modify the PropsTable component to accept a generic type export const PropsTable = >({ diff --git a/microsite-canon/components/PropsTable/getProps.ts b/microsite-canon/components/PropsTable/getProps.ts deleted file mode 100644 index 5773eaeb27..0000000000 --- a/microsite-canon/components/PropsTable/getProps.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2024 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export function getProps(styles: Record) { - return Object.keys(styles).reduce( - (acc: Record, n) => { - const style = styles[n]; - - let values: string[] = []; - - if (style.values) { - // If values exist, use them - values = Object.keys(style.values); - } else if (style.mappings && style.mappings.length > 0) { - // If mappings exist, use the first mapping's values - const firstMapping = style.mappings[0]; - values = Object.keys(styles[firstMapping].values); - } else { - // Default to an empty array if neither values nor mappings exist - values = []; - } - - acc[n] = { - type: values, - responsive: true, - }; - return acc; - }, - {} as Record, - ); -} diff --git a/microsite-canon/components/PropsTable/index.ts b/microsite-canon/components/PropsTable/index.ts index 181933f0f8..06d884c13d 100644 --- a/microsite-canon/components/PropsTable/index.ts +++ b/microsite-canon/components/PropsTable/index.ts @@ -14,4 +14,3 @@ * limitations under the License. */ export { PropsTable } from './PropsTable'; -export { getProps } from './getProps'; diff --git a/microsite-canon/components/Story/index.tsx b/microsite-canon/components/Story/index.tsx new file mode 100644 index 0000000000..a4be5e84fd --- /dev/null +++ b/microsite-canon/components/Story/index.tsx @@ -0,0 +1,21 @@ +'use client'; + +import { useTheme } from 'next-themes'; +import styles from './styles.module.css'; +export const Story = ({ id, height }: { id: string; height?: number }) => { + const { theme } = useTheme(); + + const localTheme = theme === 'dark' ? 'Dark' : 'Light'; + const chromaticId = '67584b7e8c2eb09c0422c27e-dmfbzicnkw'; + const chromaticUrl = `https://${chromaticId}.chromatic.com/iframe.html`; + const iframeUrl = `${chromaticUrl}?globals=theme%3A${localTheme}&args=&id=${id}`; + + return ( +
+