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#Toggle TypeScript Examples
The following examples show how to use
components#Toggle.
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: App.tsx From v2 with MIT License | 5 votes |
App: React.FC = () => {
const [isReady, setIsReady]: [boolean, Function] = useState(false);
const [isMobile, setIsMobile]: [boolean, Function] = useState(false);
const init = () => {
if (
window.matchMedia(
'(max-device-width: 820px) and (-webkit-min-device-pixel-ratio: 2)'
)?.matches
) {
setIsMobile(true);
}
// before the state refactoring, 'theme' had a boolean-ish ('true', 'false')
// value in localStorage, now 'theme' has a theme value ('dark', 'light'),
// to prevent the site from breaking, older 'theme' entries should be updated
const localStorageTheme: string | null = localStorage.getItem('theme');
if (localStorageTheme === 'true') {
localStorage.setItem('theme', 'dark');
} else if (localStorageTheme === 'false') {
localStorage.setItem('theme', 'light');
}
setIsReady(true);
};
useEffect(() => {
if (!isReady) init();
}, [isReady]);
return isReady ? (
<AppProvider config={config} isMobile={isMobile}>
<div className="app">
<Toggle />
<Content />
<Buttons />
<Footer />
<Particles />
</div>
</AppProvider>
) : (
<></>
);
}
Example #2
Source File: index.test.tsx From geist-ui with MIT License | 5 votes |
describe('Toggle', () => {
it('should render correctly', () => {
const wrapper = mount(<Toggle />)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should work with different sizes', () => {
const wrapper = mount(
<div>
<Toggle scale={1} />
<Toggle scale={0.2} />
<Toggle scale={2} />
<Toggle unit="10px" />
</div>,
)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should work with different status', () => {
const wrapper = mount(
<div>
<Toggle type="secondary" />
<Toggle type="success" />
<Toggle type="warning" />
<Toggle type="error" />
</div>,
)
expect(wrapper.html()).toMatchSnapshot()
})
it('should set toggle follow checked prop', async () => {
const wrapper = mount(<Toggle initialChecked={true} />)
expectToggleIsChecked(wrapper)
wrapper.setProps({ checked: false })
await updateWrapper(wrapper)
expectToggleIsUnChecked(wrapper)
wrapper.setProps({ checked: true })
await updateWrapper(wrapper)
expectToggleIsChecked(wrapper)
})
it('should trigger events when toggle changed', async () => {
let checked = false
const changeHandler = jest.fn().mockImplementation(e => (checked = e.target.checked))
const wrapper = mount(<Toggle onChange={changeHandler} />)
wrapper.find('input').simulate('change', {
...nativeEvent,
target: { checked: true },
})
await updateWrapper(wrapper)
expectToggleIsChecked(wrapper)
expect(changeHandler).toHaveBeenCalled()
expect(checked).toEqual(true)
})
it('should ignore events when toggle disabled', async () => {
const changeHandler = jest.fn()
const wrapper = mount(<Toggle onChange={changeHandler} disabled />)
wrapper.find('input').simulate('change', {
...nativeEvent,
target: { checked: true },
})
await updateWrapper(wrapper)
expectToggleIsUnChecked(wrapper)
expect(changeHandler).not.toHaveBeenCalled()
})
})