Skip to content

Commit e944623

Browse files
committedDec 23, 2021
feat(website): normalize charts properties definition
1 parent bfe8126 commit e944623

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3275
-4134
lines changed
 

‎website/src/components/controls/AngleControl.tsx

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
11
import React, { memo, useCallback } from 'react'
22
import styled from 'styled-components'
3-
import { AngleControlAttrs, Flavor } from '../../types'
3+
import { ChartProperty, Flavor } from '../../types'
44
import { Control } from './Control'
55
import { PropertyHeader } from './PropertyHeader'
66
import { TextInput } from './TextInput'
77
import { Help } from './Help'
8+
import { AngleControlConfig } from './types'
89

910
const size = 36
1011
const center = size / 2
1112
const markerSize = 6
1213

1314
interface AngleControlProps {
1415
id: string
15-
property: {
16-
name: string
17-
required?: boolean
18-
help?: string
19-
description?: string
20-
flavors: Flavor[]
21-
}
16+
property: ChartProperty
2217
flavors: Flavor[]
2318
currentFlavor: Flavor
2419
value: number
25-
options: AngleControlAttrs['controlOptions']
26-
onChange: (v: number) => void
20+
config: AngleControlConfig
21+
onChange: (value: number) => void
22+
context?: any
2723
}
2824

2925
export const AngleControl = memo(
30-
({ id, property, flavors, currentFlavor, value, options, onChange }: AngleControlProps) => {
31-
const start = options.start || 0
32-
const min = options.min || 0
33-
const max = options.max || 360
26+
({ id, property, flavors, currentFlavor, value, config, onChange }: AngleControlProps) => {
27+
const start = config.start || 0
28+
const min = config.min || 0
29+
const max = config.max || 360
3430

3531
const handleChange = useCallback(
3632
event => {

‎website/src/components/controls/ArrayControl.tsx

+22-28
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
1-
import React, { memo, Fragment, useMemo, useState, useCallback } from 'react'
1+
import React, { memo, Fragment, useMemo, useState, useCallback, MouseEvent } from 'react'
22
import styled from 'styled-components'
33
import { PropertyHeader } from './PropertyHeader'
44
import ControlsGroup from './ControlsGroup'
55
import { Cell, Toggle } from './styled'
66
import { Help } from './Help'
7+
import { Flavor, ChartProperty } from '../../types'
8+
import { ArrayControlConfig } from './types'
79

810
interface ArrayControlProps {
9-
/*
10-
property: PropTypes.object.isRequired,
11-
value: PropTypes.array.isRequired,
12-
flavors: PropTypes.arrayOf(PropTypes.oneOf(['svg', 'html', 'canvas', 'api'])).isRequired,
13-
currentFlavor: PropTypes.oneOf(['svg', 'html', 'canvas', 'api']).isRequired,
14-
options: PropTypes.shape({
15-
props: PropTypes.array.isRequired,
16-
shouldCreate: PropTypes.bool,
17-
addLabel: PropTypes.string,
18-
shouldRemove: PropTypes.bool,
19-
removeLabel: PropTypes.string,
20-
defaults: PropTypes.object,
21-
getItemTitle: PropTypes.func,
22-
}).isRequired,
23-
onChange: PropTypes.func.isRequired,
24-
*/
11+
id: string
12+
property: ChartProperty
13+
value: unknown[]
14+
flavors: Flavor[]
15+
currentFlavor: Flavor
16+
config: ArrayControlConfig
17+
onChange: (value: unknown) => void
18+
context?: any
2519
}
2620

27-
const ArrayControl = memo(
21+
export const ArrayControl = memo(
2822
({
2923
property,
3024
flavors,
3125
currentFlavor,
3226
value,
3327
onChange,
34-
options: {
28+
config: {
3529
props,
3630
shouldCreate = false,
3731
addLabel = 'add',
@@ -40,23 +34,24 @@ const ArrayControl = memo(
4034
defaults = {},
4135
getItemTitle,
4236
},
43-
}) => {
37+
}: ArrayControlProps) => {
4438
const [activeItems, setActiveItems] = useState([0])
4539
const append = useCallback(() => {
4640
onChange([...value, { ...defaults }])
4741
setActiveItems([value.length])
4842
}, [value, onChange, defaults, setActiveItems])
43+
4944
const remove = useCallback(
50-
index => event => {
45+
(index: number) => (event: MouseEvent) => {
5146
event.stopPropagation()
52-
const items = value.filter((v, i) => i !== index)
47+
const items = value.filter((_item: any, i) => i !== index)
5348
setActiveItems([])
5449
onChange(items)
5550
},
5651
[value, onChange, setActiveItems]
5752
)
5853
const change = useCallback(
59-
index => itemValue => {
54+
(index: number) => (itemValue: unknown) => {
6055
onChange(
6156
value.map((v, i) => {
6257
if (i === index) return itemValue
@@ -67,7 +62,7 @@ const ArrayControl = memo(
6762
[value, onChange]
6863
)
6964
const toggle = useCallback(
70-
index => () => {
65+
(index: number) => () => {
7166
setActiveItems(items => {
7267
if (items.includes(index)) {
7368
return items.filter(i => i !== index)
@@ -118,7 +113,6 @@ const ArrayControl = memo(
118113
controls={subProps}
119114
settings={item}
120115
onChange={change(index)}
121-
isNested={true}
122116
/>
123117
)}
124118
</Fragment>
@@ -128,8 +122,6 @@ const ArrayControl = memo(
128122
}
129123
)
130124

131-
export default ArrayControl
132-
133125
const Header = styled(Cell)`
134126
border-bottom: 1px solid ${({ theme }) => theme.colors.borderLight};
135127
@@ -144,7 +136,9 @@ const Title = styled.div`
144136
color: ${({ theme }) => theme.colors.textLight};
145137
`
146138

147-
const SubHeader = styled(Cell)`
139+
const SubHeader = styled(Cell)<{
140+
isOpened: boolean
141+
}>`
148142
cursor: pointer;
149143
font-weight: 600;
150144
user-select: none;

0 commit comments

Comments
 (0)
Please sign in to comment.