|
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; |
|
|
import { StackOffsetType } from '../util/types'; |
|
|
import { SyncMethod } from '../synchronisation/types'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type UpdatableChartOptions = { |
|
|
accessibilityLayer: boolean; |
|
|
barCategoryGap: number | string; |
|
|
barGap: number | string; |
|
|
barSize: string | number | undefined; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
className: string | undefined; |
|
|
maxBarSize: number | undefined; |
|
|
stackOffset: StackOffsetType; |
|
|
|
|
|
|
|
|
|
|
|
syncId: number | string | undefined; |
|
|
syncMethod: SyncMethod; |
|
|
}; |
|
|
|
|
|
export const initialState: UpdatableChartOptions = { |
|
|
accessibilityLayer: true, |
|
|
barCategoryGap: '10%', |
|
|
barGap: 4, |
|
|
barSize: undefined, |
|
|
className: undefined, |
|
|
maxBarSize: undefined, |
|
|
stackOffset: 'none', |
|
|
syncId: undefined, |
|
|
syncMethod: 'index', |
|
|
}; |
|
|
|
|
|
const rootPropsSlice = createSlice({ |
|
|
name: 'rootProps', |
|
|
initialState, |
|
|
reducers: { |
|
|
updateOptions: (state: UpdatableChartOptions, action: PayloadAction<UpdatableChartOptions>) => { |
|
|
state.accessibilityLayer = action.payload.accessibilityLayer; |
|
|
state.barCategoryGap = action.payload.barCategoryGap; |
|
|
state.barGap = action.payload.barGap ?? initialState.barGap; |
|
|
state.barSize = action.payload.barSize; |
|
|
state.maxBarSize = action.payload.maxBarSize; |
|
|
state.stackOffset = action.payload.stackOffset; |
|
|
state.syncId = action.payload.syncId; |
|
|
state.syncMethod = action.payload.syncMethod; |
|
|
state.className = action.payload.className; |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
|
|
|
export const rootPropsReducer = rootPropsSlice.reducer; |
|
|
|
|
|
export const { updateOptions } = rootPropsSlice.actions; |
|
|
|