{"componentChunkName":"component---src-templates-post-template-js","path":"/en-US/advanced/dark-mode","result":{"data":{"current":{"frontmatter":{"title":"Dark Mode","order":6,"brief":null,"icon":"doc-darkmode"},"fields":{"type":"advanced"},"tableOfContents":{"items":[{"url":"#dark-mode","title":"Dark mode"},{"url":"#recommended-settings","title":"Recommended settings"},{"url":"#how-to-switch","title":"How to switch"},{"url":"#keep-consistency-with-system-theme","title":"Keep Consistency with System Theme"},{"url":"#block-darklight-mode","title":"Block Dark/Light Mode"}]},"body":"var _excluded = [\"components\"];\nfunction _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }\nfunction _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }\nfunction _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }\n/* @jsxRuntime classic */\n/* @jsx mdx */\n\nvar _frontmatter = {\n  \"category\": \"Design Collaboration\",\n  \"title\": \"Dark Mode\",\n  \"subTitle\": \"Dark Mode\",\n  \"icon\": \"doc-darkmode\",\n  \"localeCode\": \"en-US\",\n  \"order\": 6\n};\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\nvar Compare = makeShortcode(\"Compare\");\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n    props = _objectWithoutProperties(_ref, _excluded);\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"section\", null, mdx(\"h2\", {\n    parentName: \"section\"\n  }, \"Dark mode\"), mdx(\"p\", {\n    parentName: \"section\"\n  }, \"\\uD83E\\uDD29  Semi's default theme or custom themes configured through \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https:/lf3-static.semi.design/obj/semi-tos/semi_main/dsm\"\n  }, \"Semi DSM\"), \" come with both light and dark modes, which can be easily switched.\", mdx(\"br\", {\n    parentName: \"p\"\n  }), \"\\n\", \"\\uD83C\\uDF12 Semi also supports the use of dark mode in a partial area of the page.  \"), mdx(Compare, {\n    dark: \"https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/dsm/dark.png\",\n    light: \"https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/dsm/light.png\\n\",\n    mdxType: \"Compare\"\n  })), mdx(\"section\", null, mdx(\"h2\", {\n    parentName: \"section\"\n  }, \"Recommended settings\"), mdx(\"p\", {\n    parentName: \"section\"\n  }, \"Semi will automatically mount the global color palette on the body element. We have built in some commonly used CSS Tokens. For detailed Token details, please refer to \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https:/lf3-static.semi.design/obj/semi-tos/semi_main/en-US/basic/tokens\"\n  }, \"Design Variables\"), \"\\nWe recommend that you configure \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"color\"), \" and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"background-color\"), \" on the body, your business components can automatically inherit the default background color and text color from the body, and adaptive light/dark color switching\"), mdx(\"pre\", {\n    parentName: \"section\"\n  }, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-css\"\n  }, \"// css\\nbody {\\n     color: var(--semi-color-text-0);\\n     background-color: var( --semi-color-bg-0);\\n}\\n\"))), mdx(\"section\", null, mdx(\"h2\", {\n    parentName: \"section\"\n  }, \"How to switch\"), mdx(\"p\", {\n    parentName: \"section\"\n  }, \"To use Dark Mode, you could simply add \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"[theme-mode='dark']\"), \" to \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"body\"), \" in any way you prefer. Here is a quick idea:\"), mdx(\"pre\", {\n    parentName: \"section\"\n  }, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-jsx\"\n  }, \"const body = document.body;\\nif (body.hasAttribute('theme-mode')) {\\n    body.removeAttribute('theme-mode');\\n} else {\\n    body.setAttribute('theme-mode', 'dark');\\n}\\n\")), mdx(\"p\", {\n    parentName: \"section\"\n  }, \"For instance:\"), mdx(\"pre\", {\n    parentName: \"section\"\n  }, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-jsx\",\n    \"metastring\": \"live=true\",\n    \"live\": \"true\"\n  }, \"import React from 'react';\\nimport { Button } from '@douyinfe/semi-ui';\\n\\nfunction Demo() {\\n    const switchMode = () => {\\n        const body = document.body;\\n        if (body.hasAttribute('theme-mode')) {\\n            body.removeAttribute('theme-mode');\\n            // Notify our site to update current mode\\n            window.setMode('light');\\n        } else {\\n            body.setAttribute('theme-mode', 'dark');\\n            // Notify our site to update current mode\\n            window.setMode('dark');\\n        }\\n    };\\n\\n    return (\\n        <Button\\n            onClick={switchMode}\\n        >\\n            Switch Mode\\n        </Button>\\n    );\\n}\\n\"))), mdx(\"section\", null, mdx(\"h2\", {\n    parentName: \"section\"\n  }, \"Keep Consistency with System Theme\"), mdx(\"p\", {\n    parentName: \"section\"\n  }, \"If you want the mode of the site to change with the system setting, you may find this property  \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme\"\n  }, \"Prefers-color-scheme\\n\"), \" helpful. Please pay attention that this property is experimental. It asks for browser compatibility (Chrome >= 76, Safari >= 12.1) and you may expect behavior to change in the future.\"), mdx(\"p\", {\n    parentName: \"section\"\n  }, \"To change system setting in macOS, go to System Preferences -> General -> Appearance\"), mdx(\"p\", {\n    parentName: \"section\"\n  }, \"Since we do not recommend modifying the content of the npm theme package directly, you could add a listener for this property using js. Here is another example:\"), mdx(\"pre\", {\n    parentName: \"section\"\n  }, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-jsx\"\n  }, \"const mql = window.matchMedia('(prefers-color-scheme: dark)');\\n\\nfunction matchMode(e) {\\n    const body = document.body;\\n    if (e.matches) {\\n        if (!body.hasAttribute('theme-mode')) {\\n            body.setAttribute('theme-mode', 'dark');\\n        }\\n    } else {\\n        if (body.hasAttribute('theme-mode')) {\\n            body.removeAttribute('theme-mode');\\n        }\\n    }\\n}\\n\\nmql.addListener(matchMode);\\n\"))), mdx(\"section\", null, mdx(\"h2\", {\n    parentName: \"section\"\n  }, \"Block Dark/Light Mode\"), mdx(\"p\", {\n    parentName: \"section\"\n  }, \"Semi 2.0 natively supports block dark/bright color mode, and you can add \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \".semi-always-dark\"), \" or \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \".semi-always-light\"), \" to areas that require block dark or bright colors as needed.\"), mdx(\"blockquote\", {\n    parentName: \"section\"\n  }, mdx(\"p\", {\n    parentName: \"blockquote\"\n  }, \"Note: this is not work for pop-up layers or components\")), mdx(\"pre\", {\n    parentName: \"section\"\n  }, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-jsx\",\n    \"metastring\": \"live=true dir=\\\"column\\\" hideInDSM\",\n    \"live\": \"true\",\n    \"dir\": \"\\\"column\\\"\",\n    \"hideInDSM\": true\n  }, \"import React from 'react';\\nimport { Layout, Nav, Button, Breadcrumb, Avatar, Steps, Pagination, Row, Badge, Tag, Rating, Tooltip, Timeline, Popover } from '@douyinfe/semi-ui';\\nimport { IconSemiLogo, IconCamera, IconBell, IconHelpCircle, IconBytedanceLogo, IconHome, IconHistogram, IconLive, IconSetting, IconEdit, IconList } from '@douyinfe/semi-icons';\\n() => {\\n    const { Header, Footer, Sider, Content } = Layout;\\n    const [mode, setMode] = useState('semi-always-dark');\\n\\n    const switchMode = () => {\\n        const newMode = mode === 'semi-always-dark' ? 'semi-always-light' : 'semi-always-dark';\\n        setMode(newMode);\\n    };\\n\\n    const rowStyle = { margin: '16px 10px' };\\n    const badgeStyle = {\\n        width: '42px',\\n        height: '42px',\\n        borderRadius: '4px',\\n        display: 'inline-block',\\n    };\\n    const tagStyle = { marginRight: 8, marginBottom: 8 };\\n\\n    return (\\n        <>\\n            <Button\\n                onClick={switchMode}\\n                style={{ marginBottom: 4 }}\\n            >\\n                Switch Content Mode\\n            </Button>\\n            <Layout style={{ border: '1px solid var(--semi-color-border)' }}>\\n                <Header style={{ backgroundColor: 'var(--semi-color-bg-1)' }}>\\n                    <div >\\n                        <Nav mode='horizontal' defaultSelectedKeys={['Home']}>\\n                            <Nav.Header>\\n                                <IconSemiLogo style={{ fontSize: 36 }} />\\n                            </Nav.Header>\\n                            <span\\n                                style={{\\n                                    color: 'var(--semi-color-text-2)'\\n                                }}\\n                            >\\n                                <span\\n                                    style={{\\n                                        marginRight: '24px',\\n                                        color: 'var(--semi-color-text-0)',\\n                                        fontWeight: '600',\\n                                    }}>Semi Design</span>\\n                                <span style={{ marginRight: '24px' }}>Semi Theme</span>\\n                                <span>Semi Blocks</span>\\n                            </span>\\n                            <Nav.Footer>\\n                                <Button\\n                                    theme=\\\"borderless\\\"\\n                                    icon={<IconBell size=\\\"large\\\" />}\\n                                    style={{\\n                                        color: 'var(--semi-color-text-2)',\\n                                        marginRight: '12px',\\n                                    }}\\n                                />\\n                                <Button\\n                                    theme=\\\"borderless\\\"\\n                                    icon={<IconHelpCircle size=\\\"large\\\" />}\\n                                    style={{\\n                                        color: 'var(--semi-color-text-2)',\\n                                        marginRight: '12px',\\n                                    }}\\n                                />\\n                                <Avatar color='orange' size='small'>YJ</Avatar>\\n                            </Nav.Footer>\\n                        </Nav>\\n                    </div>\\n                </Header>\\n                <Layout >\\n                    <Sider style={{ backgroundColor: 'var(--semi-color-bg-1)' }}>\\n                        <Nav\\n                            style={{ maxWidth: 220, height: '100%' }}\\n                            defaultSelectedKeys={['Home']}\\n                            items={[\\n                                { itemKey: 'Home', text: 'Home', icon: <IconHome size=\\\"large\\\" /> },\\n                                { itemKey: 'Histogram', text: 'Histogram', icon: <IconHistogram size=\\\"large\\\" /> },\\n                                { itemKey: 'Live', text: 'Live', icon: <IconLive size=\\\"large\\\" /> },\\n                                { itemKey: 'Setting', text: 'Setting', icon: <IconSetting size=\\\"large\\\" /> },\\n                            ]}\\n                            footer={{\\n                                collapseButton: true,\\n                            }}\\n                        />\\n                    </Sider>\\n                    <Content\\n                        className={mode}\\n                        style={{\\n                            padding: '24px',\\n                            backgroundColor: 'var(--semi-color-bg-1)'\\n                        }}\\n                    >\\n                        <Breadcrumb\\n                            style={{\\n                                marginBottom: '24px'\\n                            }}\\n                            routes={['Home', 'Page Section', 'Detail']}\\n                        />\\n                        <div\\n                            style={{\\n                                borderRadius: '10px',\\n                                border: '1px solid var(--semi-color-border)',\\n                                height: '700px',\\n                                padding: '32px'\\n                            }}\\n                        >\\n                            <Row style={rowStyle}>\\n                                <div id='popup-layer'></div>\\n                                <Nav\\n                                    mode={'horizontal'}\\n                                    getPopupContainer={() => document.querySelector('#popup-layer')}\\n                                    items={[\\n                                        { itemKey: 'user', text: 'Option1', icon: <IconEdit /> },\\n                                        { itemKey: 'union', text: 'Option2', icon: <IconCamera /> },\\n                                        {\\n                                            itemKey: 'approve-management',\\n                                            text: 'Group3',\\n                                            icon: <IconList />,\\n                                            items: [\\n                                                '3-1',\\n                                                '3-2'\\n                                            ]\\n                                        },\\n                                    ]}\\n                                />\\n                                <br /><br />\\n                                <Pagination total={80} showSizeChanger></Pagination>\\n                                <br />\\n                                <Steps current={1}>\\n                                    <Steps.Step title=\\\"Finished\\\" description=\\\"This is a description.\\\" />\\n                                    <Steps.Step title=\\\"In Progress\\\" description=\\\"This is a description.\\\" />\\n                                    <Steps.Step title=\\\"Waiting\\\" description=\\\"This is a description.\\\" />\\n                                </Steps>\\n                                <br />\\n                                <Steps current={1} status=\\\"error\\\">\\n                                    <Steps.Step title=\\\"Finished\\\" description=\\\"This is a description\\\" />\\n                                    <Steps.Step title=\\\"In Process\\\" description=\\\"This is a description\\\" />\\n                                    <Steps.Step title=\\\"Waiting\\\" description=\\\"This is a description\\\" />\\n                                </Steps>\\n                            </Row>\\n                            <Row style={rowStyle}>\\n                                <div style={{ display: 'flex' }}>\\n                                    <div style={{ padding: 8 }}>\\n                                        <Badge count={5} theme='solid' >\\n                                            <Avatar color='blue' shape='square' style={badgeStyle}>XZ</Avatar>\\n                                        </Badge>\\n                                    </div>\\n                                    <div style={{ padding: 8 }}>\\n                                        <Badge count={5} theme='light' >\\n                                            <Avatar color='cyan' shape='square' style={badgeStyle}>YB</Avatar>\\n                                        </Badge>\\n                                    </div>\\n                                    <div style={{ padding: 8 }}>\\n                                        <Badge count={5} theme='inverted'>\\n                                            <Avatar color='indigo' shape='square' style={badgeStyle}>LX</Avatar>\\n                                        </Badge>\\n                                    </div>\\n                                    <div style={{ padding: 8 }}>\\n                                        <Badge dot theme='solid' >\\n                                            <Avatar color='light-blue' shape='square' style={badgeStyle}>YZ</Avatar>\\n                                        </Badge>\\n                                    </div>\\n                                    <div style={{ padding: 8 }}>\\n                                        <Badge dot theme='light' >\\n                                            <Avatar color='teal' shape='square' style={badgeStyle}>HW</Avatar>\\n                                        </Badge>\\n                                    </div>\\n                                    <div style={{ padding: '8px', borderRadius: '4px', backgroundColor: 'var(--semi-color-fill-0)' }}>\\n                                        <Badge dot theme='inverted'>\\n                                            <Avatar color='green' shape='square' style={badgeStyle}>XM</Avatar>\\n                                        </Badge>\\n                                    </div>\\n                                </div>\\n                                <br />\\n                                <div>\\n                                    <Tag color='grey' style={tagStyle}> grey tag </Tag>\\n                                    <Tag color='blue' style={tagStyle}> blue tag </Tag>\\n                                    <Tag color='blue' type='ghost' style={tagStyle}> ghost tag </Tag>\\n                                    <Tag color='blue' type='solid' style={tagStyle}> solid tag </Tag>\\n                                    <Tag color='red' style={tagStyle}> red tag </Tag>\\n                                    <Tag color='green' style={tagStyle}> green tag </Tag>\\n                                    <Tag color='orange' style={tagStyle}> orange tag </Tag>\\n                                    <Tag color='teal' style={tagStyle}> teal tag </Tag>\\n                                    <Tag color='violet' style={tagStyle}> violet tag </Tag>\\n                                    <Tag color='white' style={tagStyle}> white tag </Tag>\\n                                </div>\\n                                <br />\\n                                <div style={{ display: 'flex', alignItems: 'center' }}>\\n                                    <Popover content={'hi semi-design'} style={{ padding: 8 }}><Tag style={{ marginRight: 8 }}>I am Popover</Tag></Popover>\\n                                    <Tooltip content={'hi semi-design'}>\\n                                        <Tag style={{ marginRight: 8 }}>I am Tooltip</Tag>\\n                                    </Tooltip>\\n                                    <Rating defaultValue={3} size='small' style={{ marginRight: 8 }} />\\n                                </div>\\n                                <br />\\n                                <Timeline>\\n                                    <Timeline.Item time='2019-07-14 10:35' type='ongoing'>\\u5BA1\\u6838\\u4E2D</Timeline.Item>\\n                                    <Timeline.Item time='2019-06-13 16:17' type='success'>\\u53D1\\u5E03\\u6210\\u529F</Timeline.Item>\\n                                    <Timeline.Item time='2019-05-14 18:34' type='error'>\\u5BA1\\u6838\\u5931\\u8D25</Timeline.Item>\\n                                </Timeline>\\n                            </Row>\\n                        </div>\\n                    </Content>\\n                </Layout>\\n                <Footer\\n                    style={{\\n                        display: 'flex',\\n                        justifyContent: 'space-between',\\n                        padding: '20px',\\n                        color: 'var(--semi-color-text-2)',\\n                        backgroundColor: 'rgba(var(--semi-grey-0), 1)',\\n                    }}\\n                >\\n                    <span\\n                        style={{\\n                            display: 'flex',\\n                            alignItems: 'center',\\n                        }}\\n                    >\\n                        <IconBytedanceLogo size=\\\"large\\\" style={{ marginRight: '8px' }} />\\n                        <span>Copyright \\xA9 2019 ByteDance. All Rights Reserved. </span>\\n                    </span>\\n                    <span>\\n                        <span style={{ marginRight: '24px' }}>Customer Service</span>\\n                        <span>Feedback</span>\\n                    </span>\\n                </Footer>\\n            </Layout>\\n        </>\\n    );\\n};\\n\"))));\n}\n;\nMDXContent.isMDXComponent = true;"}},"pageContext":{"slug":"en-US/advanced/dark-mode","next":{"fields":{"slug":"zh-CN/advanced/dark-mode"},"id":"f56b2ab8-74fb-532a-96d6-16ef5699d19a","frontmatter":{"title":"Dark Mode 暗色模式","localeCode":"zh-CN","icon":"doc-darkmode","showNew":null}},"previous":{"fields":{"slug":"zh-CN/advanced/design-to-code"},"id":"f9514cab-40f2-56ff-ba31-3950b7ad3124","frontmatter":{"title":"Design to Code 设计稿转代码","localeCode":"zh-CN","icon":"doc-code","showNew":null}}}},"staticQueryHashes":["1348983216229725","1477422646229725","3245198693229725","417590761229725","63159454229725"]}