Highlight
A highlight effect that allows you to highlight elements on hover, click or with a controlled value.
Made by imskyleenInstallation
Usage
Uncontrolled Items
By default, child items will have the highlight effect. This will map the children elements and surround them with the HighlightItem
element.
Controlled Items
Using the controlledItems
props, you place your HighlightItem
wherever you like in the Highlight
component.
Children Mode
By default, in mode
with the value children
the highlight is placed in the HighlightItem
component using Motion's layoutId
technique. This technique should be preferred in most cases. However, in some cases, you may run into z-index problems, so it's best to use the parent
mode to avoid visual bugs.
Parent Mode
By using the mode
property with the value parent
, the Highlight
component will set the highlight to absolute in Highlight
. This may be useful in some cases to avoid the visual z-index bugs you can get with mode
children
.
HighlightItem asChild
Children Mode
Parent Mode
API Reference
Highlight
Prop | Type | Default |
---|---|---|
as? | React.ElementType | div |
mode? | 'children' | 'parent' | children |
value? | string | null | - |
defaultValue? | string | null | - |
onValueChange? | (value: string | null) => void | - |
className? | string | - |
style? | React.CSSProperties | - |
transition? | Transition | { type: 'spring', stiffness: 350, damping: 35 } |
hover? | boolean | false |
click? | boolean | true |
disabled? | boolean | false |
enabled? | boolean | true |
exitDelay? | number | 0.2 |
controlledItems? | boolean | - |
itemsClassName? | string | - |
Mode: "parent"
Prop | Type | Default |
---|---|---|
boundsOffset? | Partial<Bounds> | - |
containerClassName? | string | - |
forceUpdateBounds? | boolean | - |
HighlightItem
Prop | Type | Default |
---|---|---|
as? | React.ElementType | div |
children | React.ReactElement | - |
id? | string | - |
value? | string | - |
className? | string | - |
style? | React.CSSProperties | - |
transition? | Transition | - |
activeClassName? | string | - |
disabled? | boolean | false |
exitDelay? | number | - |
asChild? | boolean | false |
forceUpdateBounds? | boolean | - |