Skip to content

Commit

Permalink
More components migration
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Dec 21, 2023
1 parent f435ab7 commit 732581c
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 65 deletions.
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 0 additions & 20 deletions src/components/FieldString.jsx

This file was deleted.

18 changes: 18 additions & 0 deletions src/components/FieldString.tsx
Original file line number Diff line number Diff line change
@@ -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<FieldStringProps> {
render() {
const {props} = this;

return <Block label={props.label}>
<InputString {...props} />
</Block>
}
}
17 changes: 8 additions & 9 deletions src/components/FieldType.jsx → src/components/FieldType.tsx
Original file line number Diff line number Diff line change
@@ -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<FieldTypeProps> {
static defaultProps = {
disabled: false,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<FilterEditorBlockProps> {
render() {
return <div className="maputnik-filter-editor-block">
<div className="maputnik-filter-editor-block-action">
Expand Down
11 changes: 5 additions & 6 deletions src/components/IconLayer.jsx → src/components/IconLayer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import PropTypes from 'prop-types'

import IconLine from './IconLine'
import IconFill from './IconFill'
Expand All @@ -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<IconLayerProps> {
render() {
const iconProps = { style: this.props.style }
switch(this.props.type) {
Expand Down
47 changes: 24 additions & 23 deletions src/components/InputColor.jsx → src/components/InputColor.tsx
Original file line number Diff line number Diff line change
@@ -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<InputColorProps> {
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);
}

Expand Down Expand Up @@ -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 = <div
className="maputnik-color-picker-offset"
style={{
position: 'fixed',
zIndex: 1,
position: 'fixed',
zIndex: 1,
left: offset.left,
top: offset.top,
}}>
<ChromePicker
color={currentColor}
color={currentChromeColor}
onChange={c => this.onChangeNoCheck(formatColor(c))}
/>
<div
Expand Down
2 changes: 1 addition & 1 deletion src/components/InputString.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

type InputStringProps = {
export type InputStringProps = {
"data-wd-key"?: string
value?: string
style?: object
Expand Down

0 comments on commit 732581c

Please sign in to comment.