diff --git a/package-lock.json b/package-lock.json index d489f929..aa242d6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -67,12 +67,14 @@ "@storybook/react": "^7.6.5", "@storybook/react-vite": "^7.6.5", "@storybook/theming": "^7.6.5", + "@types/color": "^3.0.6", "@types/cors": "^2.8.17", "@types/lodash.isequal": "^4.5.8", "@types/lodash.throttle": "^4.1.9", "@types/react": "^16.14.52", "@types/react-aria-modal": "^4.0.9", "@types/react-autocomplete": "^1.8.9", + "@types/react-color": "^3.0.10", "@types/react-dom": "^16.9.24", "@types/react-icon-base": "^2.1.6", "@types/uuid": "^9.0.7", @@ -4586,6 +4588,30 @@ "@types/chai": "*" } }, + "node_modules/@types/color": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/@types/color/-/color-3.0.6.tgz", + "integrity": "sha512-NMiNcZFRUAiUUCCf7zkAelY8eV3aKqfbzyFQlXpPIEeoNDbsEHGpb854V3gzTsGKYj830I5zPuOwU/TP5/cW6A==", + "dev": true, + "dependencies": { + "@types/color-convert": "*" + } + }, + "node_modules/@types/color-convert": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@types/color-convert/-/color-convert-2.0.3.tgz", + "integrity": "sha512-2Q6wzrNiuEvYxVQqhh7sXM2mhIhvZR/Paq4FdsQkOMgWsCIkKvSGj8Le1/XalulrmgOzPMqNa0ix+ePY4hTrfg==", + "dev": true, + "dependencies": { + "@types/color-name": "*" + } + }, + "node_modules/@types/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-87W6MJCKZYDhLAx/J1ikW8niMvmGRyY+rpUxWpL1cO7F8Uu5CHuQoFv+R0/L5pgNdW4jTyda42kv60uwVIPjLw==", + "dev": true + }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -4852,6 +4878,16 @@ "@types/react": "*" } }, + "node_modules/@types/react-color": { + "version": "3.0.10", + "resolved": "https://registry.npmjs.org/@types/react-color/-/react-color-3.0.10.tgz", + "integrity": "sha512-6K5BAn3zyd8lW8UbckIAVeXGxR82Za9jyGD2DBEynsa7fKaguLDVtjfypzs7fgEV7bULgs7uhds8A8v1wABTvQ==", + "dev": true, + "dependencies": { + "@types/react": "*", + "@types/reactcss": "*" + } + }, "node_modules/@types/react-dom": { "version": "16.9.24", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.9.24.tgz", @@ -4870,6 +4906,15 @@ "@types/react": "*" } }, + "node_modules/@types/reactcss": { + "version": "1.2.11", + "resolved": "https://registry.npmjs.org/@types/reactcss/-/reactcss-1.2.11.tgz", + "integrity": "sha512-0fFy0ubuPlhksId8r9V8nsLcxBAPQnn15g/ERAElgE9L6rOquMj2CapsxqfyBuHlkp0/ndEUVnkYI7MkTtkGpw==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, "node_modules/@types/resolve": { "version": "1.20.6", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.6.tgz", diff --git a/package.json b/package.json index 2c3b67eb..9c4be94b 100644 --- a/package.json +++ b/package.json @@ -96,12 +96,14 @@ "@storybook/react": "^7.6.5", "@storybook/react-vite": "^7.6.5", "@storybook/theming": "^7.6.5", + "@types/color": "^3.0.6", "@types/cors": "^2.8.17", "@types/lodash.isequal": "^4.5.8", "@types/lodash.throttle": "^4.1.9", "@types/react": "^16.14.52", "@types/react-aria-modal": "^4.0.9", "@types/react-autocomplete": "^1.8.9", + "@types/react-color": "^3.0.10", "@types/react-dom": "^16.9.24", "@types/react-icon-base": "^2.1.6", "@types/uuid": "^9.0.7", diff --git a/src/components/FieldString.jsx b/src/components/FieldString.jsx deleted file mode 100644 index 89d93274..00000000 --- a/src/components/FieldString.jsx +++ /dev/null @@ -1,20 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' -import Block from './Block' -import InputString from './InputString' - -export default class FieldString extends React.Component { - static propTypes = { - ...InputString.propTypes, - name: PropTypes.string, - } - - render() { - const {props} = this; - - return - - - } -} - diff --git a/src/components/FieldString.tsx b/src/components/FieldString.tsx new file mode 100644 index 00000000..bc5a137e --- /dev/null +++ b/src/components/FieldString.tsx @@ -0,0 +1,18 @@ +import React from 'react' +import Block from './Block' +import InputString, {InputStringProps} from './InputString' + +type FieldStringProps = InputStringProps & { + name?: string + label?: string +}; + +export default class FieldString extends React.Component { + render() { + const {props} = this; + + return + + + } +} diff --git a/src/components/FieldType.jsx b/src/components/FieldType.tsx similarity index 78% rename from src/components/FieldType.jsx rename to src/components/FieldType.tsx index 8d57ef42..da954907 100644 --- a/src/components/FieldType.jsx +++ b/src/components/FieldType.tsx @@ -1,20 +1,19 @@ import React from 'react' -import PropTypes from 'prop-types' import {latest} from '@maplibre/maplibre-gl-style-spec' import Block from './Block' import InputSelect from './InputSelect' import InputString from './InputString' -export default class FieldType extends React.Component { - static propTypes = { - value: PropTypes.string.isRequired, - wdKey: PropTypes.string, - onChange: PropTypes.func.isRequired, - error: PropTypes.object, - disabled: PropTypes.bool, - } +type FieldTypeProps = { + value: string + wdKey?: string + onChange(...args: unknown[]): unknown + error?: unknown[] | undefined + disabled?: boolean +}; +export default class FieldType extends React.Component { static defaultProps = { disabled: false, } diff --git a/src/components/FilterEditorBlock.jsx b/src/components/FilterEditorBlock.tsx similarity index 73% rename from src/components/FilterEditorBlock.jsx rename to src/components/FilterEditorBlock.tsx index 7f02b6c3..021b52ab 100644 --- a/src/components/FilterEditorBlock.jsx +++ b/src/components/FilterEditorBlock.tsx @@ -1,14 +1,12 @@ import React from 'react' -import PropTypes from 'prop-types' import InputButton from './InputButton' import {MdDelete} from 'react-icons/md' -export default class FilterEditorBlock extends React.Component { - static propTypes = { - onDelete: PropTypes.func.isRequired, - children: PropTypes.element.isRequired, - } +type FilterEditorBlockProps = { + onDelete(...args: unknown[]): unknown +}; +export default class FilterEditorBlock extends React.Component { render() { return
diff --git a/src/components/IconLayer.jsx b/src/components/IconLayer.tsx similarity index 83% rename from src/components/IconLayer.jsx rename to src/components/IconLayer.tsx index fafb1270..e92160ad 100644 --- a/src/components/IconLayer.jsx +++ b/src/components/IconLayer.tsx @@ -1,5 +1,4 @@ import React from 'react' -import PropTypes from 'prop-types' import IconLine from './IconLine' import IconFill from './IconFill' @@ -8,12 +7,12 @@ import IconBackground from './IconBackground' import IconCircle from './IconCircle' import IconMissing from './IconMissing' -export default class IconLayer extends React.Component { - static propTypes = { - type: PropTypes.string.isRequired, - style: PropTypes.object, - } +type IconLayerProps = { + type: string + style?: object +}; +export default class IconLayer extends React.Component { render() { const iconProps = { style: this.props.style } switch(this.props.type) { diff --git a/src/components/InputColor.jsx b/src/components/InputColor.tsx similarity index 79% rename from src/components/InputColor.jsx rename to src/components/InputColor.tsx index 02fb0965..7c919edd 100644 --- a/src/components/InputColor.jsx +++ b/src/components/InputColor.tsx @@ -1,36 +1,37 @@ import React from 'react' import Color from 'color' import ChromePicker from 'react-color/lib/components/chrome/Chrome' -import PropTypes from 'prop-types' +import {ColorResult} from 'react-color'; import lodash from 'lodash'; -function formatColor(color) { +function formatColor(color: ColorResult): string { const rgb = color.rgb return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${rgb.a})` } -/*** Number fields with support for min, max and units and documentation*/ -export default class InputColor extends React.Component { - static propTypes = { - onChange: PropTypes.func.isRequired, - name: PropTypes.string, - value: PropTypes.string, - doc: PropTypes.string, - style: PropTypes.object, - default: PropTypes.string, - 'aria-label': PropTypes.string, - } +type InputColorProps = { + onChange(...args: unknown[]): unknown + name?: string + value?: string + doc?: string + style?: object + default?: string + 'aria-label'?: string +}; +/*** Number fields with support for min, max and units and documentation*/ +export default class InputColor extends React.Component { state = { pickerOpened: false } + colorInput: HTMLInputElement | null = null; - constructor () { - super(); + constructor (props: InputColorProps) { + super(props); this.onChangeNoCheck = lodash.throttle(this.onChangeNoCheck, 1000/30); } - onChangeNoCheck (v) { + onChangeNoCheck(v: string) { this.props.onChange(v); } @@ -68,31 +69,31 @@ export default class InputColor extends React.Component { } } - onChange (v) { + onChange (v: string) { this.props.onChange(v === "" ? undefined : v); } render() { const offset = this.calcPickerOffset() - var currentColor = this.color.object() - currentColor = { + const currentColor = this.color.object(); + const currentChromeColor = { r: currentColor.r, g: currentColor.g, b: currentColor.b, // Rename alpha -> a for ChromePicker - a: currentColor.alpha + a: currentColor.alpha! } const picker =
this.onChangeNoCheck(formatColor(c))} />