components APIs
- Header
- Button
- Layout
- Footer
- Text
- Box
- Card
- Table
- Loading
- Select
- Loader
- Toolbar
- Icon
- CodeInput
- BottomSheet
- InfoBlock
- LanguageToggle
- ProgressCircles
- Ripple
- Toggle
- Tag
- Input
- Paginator
- Filter
- AsyncSelect
- CatalogBigButton
- ReadMore
- ConditionalWrapper
- LastCheckedDisplay
- PriceLabel
- PageTitle
- CartTable
- CartFinalPriceTable
- LoadingSpin
- InfoModal
- ProductCard
- RecommendCoupon
- PriceVales
- NomalLayout
- Web3ReactManager
- Popups
- CurrencyInput
- TransactionErrorContent
- TransactionConfirmationModal
- ConfirmationModalContent
- DoubleCurrencyLogo
- CustomModal
- CurrencySearchModal
- CurrencyLogo
- NumericalInput
- Logo
- QuestionHelper
- ListLogo
- DataTable
- WalletModal
- CustomTable
- MinimalPositionCard
- RemoveLiquidityModal
- CustomTooltip
- ColoredSlider
- ToggleSwitch
- FormattedPriceImpact
- SettingsModal
- ConfirmSwapModal
- AdvancedSwapDetails
- AddressInput
- LineChart
- StakeSyrupModal
- AccountDetails
- BetaWarningBanner
- AreaChart
- ChartType
- TokensTable
- PairTable
- TopMovers
- BarChart
- TransactionsTable
- StakeQuickModal
- UnstakeQuickModal
- SyrupCard
- CustomMenu
- SearchInput
- CustomSwitch
- FarmCard
- BuyFiatModal
- MoonpayModal
- RewardSlider
- Swap
- AddLiquidity
- PoolFinderModal
- PoolPositionCard
- SwapTokenDetails
- SuperHeader
- GlobalStyles
- PrimaryButton
- SectionTitle
- Section
- AccentSection
- ChainSelection
- CoinSelection
- AddressSelection
- SendAction
- Buttons
- Content
- Particles
- IconButton
- NotSupported
- InputSearch
- RouteGuard
- SearchBar
- FileInput
- GovBanner
- AuthForm
- DomainDetails
- Subnav
- ColumnFilter
- ImportExport
- selectFilter
- TaggedArrayInput
- FacetFilter
- ButtonSingleLine
- TextMultiline
- ButtonSelect
- BottomSheetBehavior
- InfoButton
- BulletPointX
- BulletPointCheck
- Title
- LoadingIcon
- SelectFilterControls
- CORInputForm
- SdnInputForm
- Navbar
- HomeRoute
- AuthRoute
- DocumentDetails
- DocumentStepper
- AddGame
- Auth
- Effectiveness
- Export
- PokemonType
- Moves
- Member
- MoveSelector
- Type
- Natures
- Move
- PokeInfo
- Share
- Badges
- Status
- UpdateSW
- About
- Builder
- Calculator
- Changelog
- Import
- Pokestats
- Report
- Rules
- Settings
- Tracker
- DarkThemeProvider
- NotificationHandler
- Background
- Indicator
- StyledButton
- StyledText
- Illustration
- OnboardingSlider
- FlexList
- AppLayout
- ScrollableList
- Visualization
- DataSearch
- Region
- App
- CompareApiLegend
- CompareApiBreadcrumbs
- CompareApiLink
- CompareApiCard
- ExploreApiBreadcrumbs
- ExploreApiLink
- ExploreApiSearch
- ExploreApiConst
- ApiLoader
- RefreshButton
- Listing
- PriceModal
- ConfirmationModal
- Transition
- AutoComplete
- useInput
- Avatar
- Badge
- Breadcrumbs
- ButtonDropdown
- ButtonGroup
- Capacity
- Checkbox
- Code
- Collapse
- CssBaseline
- GeistProvider
- Description
- Display
- Divider
- Dot
- Drawer
- useModal
- Fieldset
- Grid
- Image
- Keyboard
- Link
- Modal
- Note
- Page
- Pagination
- Popover
- Progress
- Radio
- Rating
- Slider
- Snippet
- Spacer
- Spinner
- Tabs
- Textarea
- Tooltip
- Tree
- useBodyScroll
- useClasses
- useClickAway
- useClipboard
- useCurrentState
- useKeyboard
- KeyMod
- KeyCode
- useMediaQuery
- useTabs
- useToasts
- User
- useTheme
- Themes
- GeistUIThemes
- useAllThemes
- CollapsableDialog
- Map
- IPForm
- IPMenu
- Container
- Parallax
- Nav
- SEO
- BlogNav
- ExtensionCard
- MenuComp
Other Related APIs
components#Snippet TypeScript Examples
The following examples show how to use
components#Snippet.
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: icons-gallery.tsx From geist-ui with MIT License | 6 votes |
ImportSnippet: React.FC<React.PropsWithChildren<unknown>> = ({ children }) => {
return (
<Snippet>
{children}
<style jsx>{`
:global(pre:before) {
display: none;
}
`}</style>
</Snippet>
)
}
Example #2
Source File: index.test.tsx From geist-ui with MIT License | 4 votes |
describe('Snippet', () => {
beforeAll(() => {
window.getSelection = jest.fn().mockImplementation(() => ({
removeAllRanges: jest.fn(),
addRange: jest.fn(),
}))
document.createRange = jest.fn().mockImplementation(() => ({
selectNode: jest.fn(),
}))
})
it('should render correctly', () => {
const wrapper = mount(<Snippet text={command} />)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should work with multi-line', () => {
const wrapper = mount(<Snippet text={multiLine} />)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should work with different styles', () => {
const wrapper = mount(
<div>
<Snippet text={command} filled />
<Snippet text={command} width="20%" />
<Snippet text={command} type="secondary" />
<Snippet text={command} type="success" filled />
</div>,
)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('text should be copied', () => {
document.execCommand = jest.fn()
const wrapper = mount(<Snippet text={command} />)
wrapper.find('.copy').simulate('click')
expect(document.execCommand).toHaveBeenCalled()
;(document.execCommand as jest.Mock).mockRestore()
})
it('multi-line commands should be copied', () => {
document.execCommand = jest.fn()
const wrapper = mount(<Snippet text={multiLine} />)
wrapper.find('.copy').simulate('click')
expect(document.execCommand).toHaveBeenCalled()
;(document.execCommand as jest.Mock).mockRestore()
})
it('child commands should be copied', () => {
document.execCommand = jest.fn()
const wrapper = mount(<Snippet>{command}</Snippet>)
wrapper.find('.copy').simulate('click')
expect(document.execCommand).toHaveBeenCalled()
;(document.execCommand as jest.Mock).mockRestore()
})
it('should disable copy function', () => {
const wrapper = mount(<Snippet text={command} copy="prevent" />)
expect(wrapper.find('.copy').length).toBe(0)
})
it('should work with custom symbol', () => {
const wrapper = mount(<Snippet text={command} symbol=">" />)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
const emptySymbolWrapper = mount(<Snippet text={command} symbol=" " />)
expect(emptySymbolWrapper.html()).toMatchSnapshot()
const emptySymbolWrapper2 = mount(<Snippet text={command} symbol="" />)
expect(emptySymbolWrapper2.html()).toEqual(emptySymbolWrapper.html())
expect(() => emptySymbolWrapper.unmount()).not.toThrow()
expect(() => emptySymbolWrapper2.unmount()).not.toThrow()
})
it('should work with custom toast', () => {
document.execCommand = jest.fn()
const wrapper = mount(
<Snippet text={command} toastText="Code copied!" toastType="secondary" />,
)
wrapper.find('.copy').simulate('click')
expect(document.execCommand).toHaveBeenCalled()
;(document.execCommand as jest.Mock).mockRestore()
})
afterAll(() => {
;(window.getSelection as jest.Mock).mockRestore()
;(document.createRange as jest.Mock).mockRestore()
})
})