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
- react#useState
- react#useEffect
- react#useCallback
- react#ReactNode
- react#createContext
- react#useMemo
- react#useRef
- react#ComponentType
- react-dom#createPortal
- react-transition-group#TransitionGroup
- types#ProviderProps
- types#AlertTimer
- types#AlertInstance
- types#AlertOptions
- types#TemplateAlertOptions
- types#AlertContainerFactory
components#Transition TypeScript Examples
The following examples show how to use
components#Transition.
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: Alert.tsx From gear-js with GNU General Public License v3.0 | 4 votes |
AlertProvider = ({ children, template: Template, containerClassName }: Props) => {
const root = useRef<HTMLDivElement | null>(null);
const timers = useRef<AlertTimer>(new Map());
const [alerts, setAlerts] = useState<AlertInstance[]>([]);
const removeTimer = useCallback((alertId: string) => {
const timerId = timers.current.get(alertId);
if (timerId) {
clearTimeout(timerId);
timers.current.delete(alertId);
}
}, []);
const remove = useCallback(
(alertId: string) => {
removeTimer(alertId);
setAlerts((prevState) => prevState.filter((alert) => alert.id !== alertId));
},
[removeTimer],
);
const createTimer = useCallback(
(alertId: string, timeout = 0) => {
if (timeout > 0) {
const timerId = setTimeout(() => remove(alertId), timeout);
timers.current.set(alertId, timerId);
}
},
[remove],
);
const show = useCallback(
(content: ReactNode, options: AlertOptions): string => {
const id = nanoid(6);
createTimer(id, options.timeout);
setAlerts((prevState) => [
...prevState,
{
id,
content,
options,
},
]);
return id;
},
[createTimer],
);
const update = useCallback(
(alertId: string, content: ReactNode, options?: AlertOptions) => {
removeTimer(alertId);
setAlerts((prevState) =>
prevState.map((alert) => {
if (alert.id !== alertId) return alert;
const updatedAlert = {
id: alert.id,
content,
options: {
...alert.options,
...options,
},
};
createTimer(updatedAlert.id, updatedAlert.options.timeout);
return updatedAlert;
}),
);
},
[removeTimer, createTimer],
);
const getAlertTemplate = useCallback(
(templateOptions: AlertOptions) => (content: ReactNode, options?: TemplateAlertOptions) =>
show(content, {
...templateOptions,
...options,
}),
[show],
);
const alertContext = useMemo(
() => ({
update,
remove,
info: getAlertTemplate(DEFAULT_INFO_OPTIONS),
error: getAlertTemplate(DEFAULT_ERROR_OPTIONS),
success: getAlertTemplate(DEFAULT_SUCCESS_OPTIONS),
loading: getAlertTemplate(DEFAULT_LOADING_OPTIONS),
}),
[update, remove, getAlertTemplate],
);
useEffect(() => {
root.current = document.createElement('div');
root.current.id = 'alert-root';
containerClassName && root.current.classList.add(containerClassName);
document.body.appendChild(root.current);
}, []);
return (
<>
<AlertContext.Provider value={alertContext}>{children}</AlertContext.Provider>
{root.current &&
createPortal(
<TransitionGroup appear>
{alerts.map((alert) => (
<Transition key={alert.id}>
<Template alert={alert} close={() => remove(alert.id)} />
</Transition>
))}
</TransitionGroup>,
root.current,
)}
</>
);
}