import * as React from 'react'; import { Link } from '@fluentui/react-components'; import type { JSXElement } from '@fluentui/react-utilities'; import { getParameters } from 'codesandbox-import-utils/lib/api/define'; import dedent from 'dedent'; import { getBrandValues, objectToString } from '../../utils/toString'; import { useThemeDesigner } from '../../Context/ThemeDesignerContext'; const defaultFileToPreview = encodeURIComponent('/index.tsx'); export const ExportLink = (): JSXElement => { const { state: { themeName, brand, darkThemeOverrides, lightThemeOverrides }, } = useThemeDesigner(); const content = dedent` import * as React from "react"; import { makeStaticStyles, makeStyles, shorthands, tokens, Avatar, Badge, Body1, Button, Caption1, Caption2, Checkbox, FluentProvider, Input, Menu, MenuButton, MenuItemCheckbox, MenuList, MenuPopover, MenuTrigger, Radio, RadioGroup, Slider, Switch, Tab, TabList, Title3, useId, Dropdown, Option } from "@fluentui/react-components"; import type { Theme } from "@fluentui/react-components"; import { bundleIcon, CalendarLtrFilled, CalendarLtrRegular, ChevronRightRegular, MeetNowFilled, MeetNowRegular, SearchRegular, } from "@fluentui/react-icons"; export interface ContentProps { lightTheme: Theme; darkTheme: Theme; } const useStaticStyles = makeStaticStyles({ body: { position: "fixed", margin: "0px", top: "0px", left: "0px", height: "100vh" } }); const useStyles = makeStyles({ root: { display: "grid", gridTemplateRows: "50vh 50vh" }, row: { height: "50vh", display: "grid", alignItems: "start", justifyContent: "center", gridTemplateColumns: "repeat(3, 1fr)", gridTemplateRows: "auto", gridColumnGap: tokens.spacingHorizontalXXXL }, col2: { display: 'flex', flexDirection: 'column', alignItems: 'center', ...shorthands.gap(tokens.spacingVerticalL), }, col3: { display: 'grid', gridTemplateColumns: '1fr 1fr', gridTemplateRows: 'repeat(4, auto)', gridRowGap: tokens.spacingVerticalS, gridColumnGap: tokens.spacingHorizontalS, justifyContent: 'center', alignItems: 'center', }, twoCol: { gridColumnStart: 1, gridColumnEnd: 3, }, controls: { display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', }, icons: { display: 'grid', gridTemplateColumns: 'auto auto', gridTemplateRows: 'auto auto', gridRowGap: tokens.spacingVerticalS, gridColumnGap: tokens.spacingHorizontalS, justifyContent: 'center', }, avatar: { display: 'flex', ...shorthands.gap(tokens.spacingVerticalL), }, avatarText: { display: 'flex', flexDirection: 'column', justifyContent: 'left', }, }); export const Column1 = () => { const styles = useStyles(); return (
Make an impression Make a big impression with this clean, modern, and mobile-friendly site. Use it to communicate information to people inside or outside your team. Share your ideas, results, and more in this visually compelling format.
Cameron Evans Senior Researcher at Contoso
); }; export const DemoMenu = () => { const CutIcon = bundleIcon(CutFilled, CutRegular); const PasteIcon = bundleIcon(ClipboardPasteFilled, ClipboardPasteRegular); const EditIcon = bundleIcon(EditFilled, EditRegular); return ( Select } name="edit" value="cut"> Cut } name="edit" value="paste"> Paste } name="edit" value="edit"> Edit ); }; export const Column2 = () => { const styles = useStyles(); const dropdownId = useId('dropdown-default'); return (
Home Pages Documents } size="small" />} />
); }; export const DemoIcons = () => { const styles = useStyles(); const MeetNowIcon = bundleIcon(MeetNowFilled, MeetNowRegular); const CalendarLtrIcon = bundleIcon(CalendarLtrFilled, CalendarLtrRegular); return (
} /> } /> } /> } />
); }; export const Column3 = () => { const styles = useStyles(); return (
); }; export const Example: React.FC = (props) => { const styles = useStyles(); useStaticStyles(); return (
Light Theme
Dark Theme
); }; `; const indexHtmlContent = '
'; const createIndexContent = dedent` import * as ReactDOMClient from 'react-dom/client'; import { createDarkTheme, createLightTheme } from '@fluentui/react-components'; import type { BrandVariants, Theme } from '@fluentui/react-components'; import { Example } from './example'; const ${themeName}: BrandVariants = { ${objectToString(brand, '\u00A0\u00A0')} }; const lightTheme: Theme = { ...createLightTheme(${themeName}), ${getBrandValues(brand, lightThemeOverrides, themeName, '\u00A0\u00A0')} }; const darkTheme: Theme = { ...createDarkTheme(${themeName}), ${getBrandValues(brand, darkThemeOverrides, themeName, '\u00A0\u00A0')} }; darkTheme.colorBrandForeground1 = ${themeName}[110]; // use brand[110] instead of brand[100] darkTheme.colorBrandForeground2 = ${themeName}[120]; // use brand[120] instead of brand[110] ReactDOMClient.createRoot(document.getElementById('root')).render( , ); `; const packageContent = dedent` {"dependencies":{"@fluentui/react-components":"^9","react":"^18","react-dom":"^18","react-scripts":"latest"}} `; const link = React.useMemo(() => { const codeSandboxParameters = getParameters({ files: { 'example.tsx': { isBinary: false, content, }, 'index.html': { isBinary: false, content: indexHtmlContent, }, 'index.tsx': { isBinary: false, content: createIndexContent, }, 'package.json': { isBinary: false, content: packageContent, }, }, }); return `https://codesandbox.io/api/v1/sandboxes/define?parameters=${codeSandboxParameters}&query=file%3D${defaultFileToPreview}`; }, [content, createIndexContent, packageContent]); return (
Preview theme in CodeSandbox
); };