components#Spacer TypeScript Examples
The following examples show how to use
components#Spacer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.test.tsx From geist-ui with MIT License | 6 votes |
describe('Spacer', () => {
it('should render correctly', () => {
const wrapper = mount(<Spacer />)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should support x and y', () => {
const wrapper = mount(
<div>
<Spacer w={5} />
<Spacer w={15} />
<Spacer h={15} />
<Spacer h={2} />
</div>,
)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should work with float', () => {
const wrapper = mount(
<div>
<Spacer w={2.2} />
<Spacer w={1.5} />
<Spacer h={0.1} />
<Spacer h={1.8} />
</div>,
)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should work with inline mode', () => {
const wrapper = mount(<Spacer inline />)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
})
Example #2
Source File: attributes.tsx From geist-ui with MIT License | 6 votes |
Attributes: React.FC<React.PropsWithChildren<AttributesProps>> = React.memo(
({ edit, children }) => {
const { isChinese } = useConfigs()
const path = edit.replace('/pages', 'pages')
const apiTitles = useMemo(() => {
if (React.Children.count(children) === 0) return null
return (
<>
<Spacer h={1} />
<h3>
<VirtualAnchor>APIs</VirtualAnchor>
{isChinese && ' / 接口文档'}
</h3>
<AttributesTable>{children}</AttributesTable>
</>
)
}, [children, isChinese])
return (
<>
{apiTitles}
<Divider font="12px" mt="80px">
<Text p b type="secondary" style={{ userSelect: 'none' }}>
{isChinese ? '文档贡献者' : 'Contributors'}
</Text>
</Divider>
<Contributors path={path} />
</>
)
},
)
Example #3
Source File: sidebar.tsx From geist-ui with MIT License | 5 votes |
Sidebar: React.FC<Props> = React.memo(() => {
const theme = useTheme()
const boxRef = useRef<HTMLDivElement>(null)
const { sidebarScrollHeight, updateSidebarScrollHeight } = useConfigs()
const { locale, tabbar } = useLocale()
const tabbarData = useMemo(() => {
const allSides = Metadata[locale]
const currentSide = allSides.find(side => side.name === tabbar)
return (currentSide?.children || []) as Array<Sides>
}, [locale, tabbar])
useEffect(() => {
Router.events.on('routeChangeStart', () => {
if (!boxRef.current) return
updateSidebarScrollHeight(boxRef.current.scrollTop || 0)
})
}, [])
useEffect(() => {
if (!boxRef.current) return
boxRef.current.scrollTo({ top: sidebarScrollHeight })
}, [boxRef.current])
return (
<div ref={boxRef} className="sides box">
<SideItem sides={tabbarData}>
<SideGroup />
</SideItem>
<Spacer />
<style jsx>{`
.sides {
width: 100%;
padding-bottom: ${theme.layout.gap};
}
.box {
overflow-y: auto;
overflow-x: hidden;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.box::-webkit-scrollbar {
width: 0;
background-color: transparent;
}
.box > :global(.item) {
margin-bottom: ${theme.layout.gap};
}
`}</style>
</div>
)
})
Example #4
Source File: codes.tsx From geist-ui with MIT License | 4 votes |
CustomizationCodes: React.FC<unknown> = () => {
const DefaultTheme = Themes.getPresetStaticTheme()
const theme = useTheme()
const { isChinese } = useConfigs()
const codeTheme = makeCodeTheme(theme)
const { copy } = useClipboard()
const { setToast } = useToasts()
const deepDifferents = useMemo(
() => ({
...getDeepDifferents(DefaultTheme, theme),
type: CUSTOM_THEME_TYPE,
}),
[DefaultTheme, theme],
)
const userCodes = useMemo(() => {
return `const myTheme = ${JSON.stringify(deepDifferents, null, 2)}
/***
* Usage::
*
* export const App = () => {
* return (
* <GeistProvider themes={[myTheme]} themeType="${CUSTOM_THEME_TYPE}">
* <CssBaseline />
* <YourComponent />
* </GeistProvider>
* )
* }
**/`
}, [deepDifferents])
const copyCode = () => {
copy(userCodes)
setToast({ text: 'Theme code copied.' })
}
return (
<div className="custom-codes">
<h3 className="title">{isChinese ? '主题代码' : 'Theme Codes'}</h3>
<Spacer h={1} />
{isChinese ? (
<Text>
这里是你所有的变更,点击 <Code>copy</Code> 按钮即可使用在你自己的项目中。
</Text>
) : (
<Text>
This is all your changes, click <Code>copy</Code> to use it in your own project.
</Text>
)}
<Spacer h={2} />
<div className="codes">
<div className="copy" onClick={copyCode}>
<CopyIcon />
</div>
<LiveProvider code={userCodes} disabled theme={codeTheme}>
<LiveEditor />
</LiveProvider>
</div>
<Spacer h={5} />
<style jsx>{`
.custom-codes {
display: flex;
flex-direction: column;
flex: 1;
margin: 3rem auto 2.5rem;
text-align: center;
}
.title {
text-align: center;
width: 80%;
margin: 0 auto;
display: inline-block;
background: ${theme.palette.foreground};
color: ${theme.palette.background};
font-size: 1rem;
line-height: 1rem;
padding: ${theme.layout.gap} 0;
text-transform: uppercase;
letter-spacing: 1.5px;
}
.codes {
width: 80%;
margin: 0 auto;
border: 1px solid ${theme.palette.border};
border-radius: ${theme.layout.radius};
overflow: hidden;
padding: calc(0.6 * ${theme.layout.gap}) ${theme.layout.gap};
position: relative;
}
.copy {
position: absolute;
right: 1rem;
top: 1rem;
z-index: 2000;
color: ${theme.palette.accents_3};
cursor: pointer;
user-select: none;
transition: color 200ms ease;
--snippet-font-size: 16px;
}
.copy:hover {
color: ${theme.palette.accents_6};
}
@media only screen and (max-width: ${theme.layout.breakpointMobile}) {
.title,
.codes {
width: 90vw;
}
}
`}</style>
</div>
)
}
Example #5
Source File: demo.tsx From geist-ui with MIT License | 4 votes |
Demo: React.FC<React.PropsWithChildren<unknown>> = () => {
const theme = useTheme()
const { isChinese } = useConfigs()
return (
<div className="demo">
<div className="content">
{isChinese ? (
<>
<Text h2 mb={0} font="13px" type="secondary">
预览
</Text>
<Text>
这里是你变更主题后的即时预览。此外,当你每次更新主题变量时,整个文档站点也会随之变化。
</Text>
</>
) : (
<>
<Text h2 mb={0} font="13px">
PREVIEWS
</Text>
<Text>
Here's a preview of your changes to the Theme. When you set the changes,
the entire document site will change with the theme.
</Text>
</>
)}
<Spacer h={1.7} />
<Text h3 font="13px" type="secondary">
{isChinese ? '色彩' : 'COLORS'}
</Text>
<Colors />
<Spacer h={1.7} />
<Text h3 font="13px" type="secondary">
{isChinese ? '排版' : 'Typography'}
</Text>
<Text>
<Link rel="nofollow" href="https://en.wikipedia.org/wiki/HTTP/2" color>
HTTP/2
</Link>{' '}
allows the server to <Code>push</Code> content, that is, to respond with data
for more queries than the client requested. This allows the server to supply
data it knows a web browser will need to render a web page, without waiting for
the browser to examine the first response, and without the overhead of an
additional request cycle.
</Text>
<Text h6>Heading</Text>
<Text h5>Heading</Text>
<Text h4>Heading</Text>
<Text h3>Heading</Text>
<Spacer h={1.7} />
<Text h3 font="13px" type="secondary">
{isChinese ? '基础组件' : 'Basic Components'}
</Text>
<Select width="90%" placeholder="Choose one" initialValue="1">
<Select.Option value="1">Option 1</Select.Option>
<Select.Option value="2">Option 2</Select.Option>
</Select>
<Spacer h={1} />
<Grid.Container width="100%">
<Grid xs={8}>
<Button disabled auto>
Action
</Button>
</Grid>
<Grid xs={8}>
<Button auto>Action</Button>
</Grid>
<Grid xs={8}>
<Button auto type="secondary">
Action
</Button>
</Grid>
</Grid.Container>
</div>
<style jsx>{`
.demo {
width: 34%;
margin-top: calc(${theme.layout.gap} * 2);
margin-right: ${theme.layout.gap};
padding-right: ${theme.layout.gapQuarter};
position: relative;
border-right: 1px solid ${theme.palette.border};
height: auto;
transition: width 200ms ease;
}
.content {
width: 100%;
}
@media only screen and (max-width: ${theme.layout.breakpointMobile}) {
.demo {
display: none;
}
}
`}</style>
</div>
)
}
Example #6
Source File: controls.tsx From geist-ui with MIT License | 4 votes |
Controls: React.FC<unknown> = React.memo(() => {
const theme = useTheme()
const { themes } = useAllThemes()
const { switchTheme, updateChineseState } = useConfigs()
const { pathname } = useRouter()
const { locale } = useLocale()
const isChinese = useMemo(() => locale === CHINESE_LANGUAGE_IDENT, [locale])
const nextLocalePath = useMemo(() => {
const nextLocale = isChinese ? ENGLISH_LANGUAGE_IDENT : CHINESE_LANGUAGE_IDENT
return pathname.replace(locale, nextLocale)
}, [locale, pathname])
const hasCustomTheme = useMemo(() => Themes.hasUserCustomTheme(themes), [themes])
const switchThemes = (type: string) => {
switchTheme(type)
if (typeof window === 'undefined' || !window.localStorage) return
window.localStorage.setItem('theme', type)
}
const switchLanguages = () => {
updateChineseState(!isChinese)
Router.push(nextLocalePath)
}
const redirectGithub = () => {
if (typeof window === 'undefined') return
window.open(GITHUB_URL)
}
return (
<div className="wrapper">
<Keyboard
h="28px"
command
font="12px"
className="shortcuts"
title="Command + K to search.">
K
</Keyboard>
<Spacer w={0.75} />
<Button
w="28px"
h="28px"
py={0}
px={0}
onClick={switchLanguages}
title={isChinese ? '切换语言' : 'switch language'}>
<Text font="13px" style={{ fontWeight: 500 }}>
{isChinese ? 'En' : '中'}
</Text>
</Button>
<Spacer w={0.75} />
<Button
w="28px"
h="28px"
py={0}
px={0}
icon={<GitHubIcon />}
onClick={redirectGithub}
title={isChinese ? '代码仓库' : 'GitHub Repository'}
/>
<Spacer w={0.75} />
<Select
scale={0.5}
h="28px"
pure
onChange={switchThemes}
value={theme.type}
title={isChinese ? '切换主题' : 'Switch Themes'}>
<Select.Option value="light">
<span className="select-content">
<SunIcon size={14} /> {isChinese ? '明亮' : 'Light'}
</span>
</Select.Option>
<Select.Option value="dark">
<span className="select-content">
<MoonIcon size={14} /> {isChinese ? '暗黑' : 'Dark'}
</span>
</Select.Option>
{hasCustomTheme && (
<Select.Option value={CUSTOM_THEME_TYPE}>
<span className="select-content">
<UserIcon size={14} /> {CUSTOM_THEME_TYPE}
</span>
</Select.Option>
)}
</Select>
<style jsx>{`
.wrapper {
display: flex;
align-items: center;
}
.wrapper :global(kbd.shortcuts) {
line-height: 28px !important;
cursor: help;
opacity: 0.75;
border: none;
}
.wrapper :global(.select) {
width: 85px;
min-width: 85px;
}
.select-content {
width: auto;
height: 18px;
display: flex;
justify-content: space-between;
align-items: center;
}
.select-content :global(svg) {
margin-right: 10px;
margin-left: 2px;
}
`}</style>
</div>
)
})