useItem
A hook to declare a timeline item.
Use this hook to declare an HTML element as an item in the timeline.
Options
id
idid: stringA unique id to identify this item.
span
spanspan: SpanAn object representing the start and end values of the item.
disabled?
disabled?disabled?: booleanAn optional boolean to disable the interactivity of the item.
data?
data?data?: objectCustom data that can be passed to the row.
🧠 This can be passed to rows to identify their type. This type can later be used in the event callbacks to apply different behaviors to different row types.
useItem({
id: props.id,
span: props.span,
data: { type: 'timeline-item' },
})const onDragEnd = (event: DragEndEvent) => {
const updatedSpan =
event.active.data.current.getSpanFromDragEvent?.(event)
const rowType = event.active.data.current.type
if (rowType === 'timeline-row' && itemType === 'timeline-item') {
// update
}
if (rowType === 'timeline-disabled-row' && itemType === 'timeline-item') {
// don't update, and pop an error message
}
}resizeHandleWidth?
resizeHandleWidth?resizeHandleWidth?: numberAn optional resize handler width, in pixels.
defaults to the resizeHandleWidth provided to the context.
Choosing a larger or a smaller handleWidth will change the resize action's sensitivity.
Events
useItem can also receive callbacks, that will be called when the relevant event is triggered.
For example:
const onResizeMove = useCallback(() => {
const updatedSpan =
event.active.data.current.getSpanFromResizeEvent?.(event)
// update some local state with the updated-span
}, [])
useItem({
id: props.id,
span: props.span,
onResizeMove,
})onResizeStart?
onResizeMove?: (event: ResizeStartEvent) => voidtype ResizeStartEvent = {
active: Omit<Active, 'rect'>
direction: DragDirection // 'start' | 'end'
}onResizeMove?
onResizeMove?: (event: ResizeMoveEvent) => voidtype ResizeMoveEvent = {
active: Omit<Active, 'rect'>
delta: {
x: number
}
direction: DragDirection // 'start' | 'end'
}onResizeEnd?
onResizeMove?: (event: ResizeEndEvent) => voidtype ResizeEndEvent = {
active: Omit<Active, 'rect'>
delta: {
x: number
}
direction: DragDirection // 'start' | 'end'
}API
itemStyle
itemStyleitemStyle: CSSPropertiesBasic style properties that must be passed to the item wrapper element.
itemContentStyle
itemContentStyleitemContentStyle: CSSPropertiesBasic style properties that must be passed to the item's children wrapper element.
Last updated