diff --git a/cypress/e2e/modals.cy.ts b/cypress/e2e/modals.cy.ts index e5fd505f..911deef6 100644 --- a/cypress/e2e/modals.cy.ts +++ b/cypress/e2e/modals.cy.ts @@ -77,11 +77,18 @@ describe("modals", () => { }); it("name", () => { + when.click("field-doc-button-Name"); + + should.containText("spec-field-doc", "name for the style"); + }); + + it("show name specifications", () => { when.setValue(get.dataAttribute("modal:settings.name"), "foobar"); when.click("modal:settings.owner"); should.equalStyleStore((obj) => obj.name, "foobar"); }); + it("owner", () => { when.setValue(get.dataAttribute("modal:settings.owner"), "foobar"); when.click("modal:settings.name"); diff --git a/package-lock.json b/package-lock.json index 3eada999..24fa6919 100644 --- a/package-lock.json +++ b/package-lock.json @@ -67,11 +67,19 @@ "@storybook/react": "^7.6.5", "@storybook/react-vite": "^7.6.5", "@storybook/theming": "^7.6.5", + "@types/codemirror": "^5.60.15", + "@types/color": "^3.0.6", "@types/cors": "^2.8.17", + "@types/lodash.capitalize": "^4.2.9", "@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-file-reader-input": "^2.0.4", + "@types/react-icon-base": "^2.1.6", "@types/uuid": "^9.0.7", "@vitejs/plugin-react": "^4.2.0", "cors": "^2.8.5", @@ -4583,6 +4591,39 @@ "@types/chai": "*" } }, + "node_modules/@types/codemirror": { + "version": "5.60.15", + "resolved": "https://registry.npmjs.org/@types/codemirror/-/codemirror-5.60.15.tgz", + "integrity": "sha512-dTOvwEQ+ouKJ/rE9LT1Ue2hmP6H1mZv5+CCnNWu2qtiOe2LQa9lCprEY20HxiDmV/Bxh+dXjywmy5aKvoGjULA==", + "dev": true, + "dependencies": { + "@types/tern": "*" + } + }, + "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", @@ -4703,6 +4744,15 @@ "integrity": "sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==", "dev": true }, + "node_modules/@types/lodash.capitalize": { + "version": "4.2.9", + "resolved": "https://registry.npmjs.org/@types/lodash.capitalize/-/lodash.capitalize-4.2.9.tgz", + "integrity": "sha512-SV1dav/WbuI816SVig4trFz8ID/m5maVzC8I/E/DejPvmlXvIhw7Y0GWxJ03UhU6qaZOj6qQnR1xxC0mP7ZXoQ==", + "dev": true, + "dependencies": { + "@types/lodash": "*" + } + }, "node_modules/@types/lodash.isequal": { "version": "4.5.8", "resolved": "https://registry.npmjs.org/@types/lodash.isequal/-/lodash.isequal-4.5.8.tgz", @@ -4831,6 +4881,34 @@ "csstype": "^3.0.2" } }, + "node_modules/@types/react-aria-modal": { + "version": "4.0.9", + "resolved": "https://registry.npmjs.org/@types/react-aria-modal/-/react-aria-modal-4.0.9.tgz", + "integrity": "sha512-H8SU5QoB+1ldMGYRHNm1MXfzD5oD+ZdYTrwVzT+KEiFrkTqQG2QdwVc6Ro4/RixnU4LNtMpvF5HKAIfzzGJGjw==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, + "node_modules/@types/react-autocomplete": { + "version": "1.8.9", + "resolved": "https://registry.npmjs.org/@types/react-autocomplete/-/react-autocomplete-1.8.9.tgz", + "integrity": "sha512-Il8qJEKvPU0uW+HOPiRHIKxGF61RM6cM5tEnZDmM5ek78OK5kfv04AZbNyqdPsuTnwp8HIRgBnQH2RhgKILjcg==", + "dev": true, + "dependencies": { + "@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", @@ -4840,6 +4918,33 @@ "@types/react": "^16" } }, + "node_modules/@types/react-file-reader-input": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@types/react-file-reader-input/-/react-file-reader-input-2.0.4.tgz", + "integrity": "sha512-Jqrfn+w42j8t8Q3npMXXKPdk+reIM0UHLKVc3ykrA7q7bN3Z62SGhsClZX0+Edlqm66lcKwmDQl+WMm+Xor7Xg==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, + "node_modules/@types/react-icon-base": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/@types/react-icon-base/-/react-icon-base-2.1.6.tgz", + "integrity": "sha512-ebbN1JjCm6RxBd3HdI1+8VCdiOI4qMjnl9DIHWJFrB/eYLF4mzIgdL34PIqCJBLY3vlwil9v6IHQvzsa8vgMsg==", + "dev": true, + "dependencies": { + "@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", @@ -4891,6 +4996,15 @@ "integrity": "sha512-0vWLNK2D5MT9dg0iOo8GlKguPAU02QjmZitPEsXRuJXU/OGIOt9vT9Fc26wtYuavLxtO45v9PGleoL9Z0k1LHg==", "dev": true }, + "node_modules/@types/tern": { + "version": "0.23.9", + "resolved": "https://registry.npmjs.org/@types/tern/-/tern-0.23.9.tgz", + "integrity": "sha512-ypzHFE/wBzh+BlH6rrBgS5I/Z7RD21pGhZ2rltb/+ZrVM1awdZwjx7hE5XfuYgHWk9uvV5HLZN3SloevCAp3Bw==", + "dev": true, + "dependencies": { + "@types/estree": "*" + } + }, "node_modules/@types/uuid": { "version": "9.0.7", "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.7.tgz", diff --git a/package.json b/package.json index 75b11d12..fd9e9624 100644 --- a/package.json +++ b/package.json @@ -96,11 +96,19 @@ "@storybook/react": "^7.6.5", "@storybook/react-vite": "^7.6.5", "@storybook/theming": "^7.6.5", + "@types/codemirror": "^5.60.15", + "@types/color": "^3.0.6", "@types/cors": "^2.8.17", + "@types/lodash.capitalize": "^4.2.9", "@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-file-reader-input": "^2.0.4", + "@types/react-icon-base": "^2.1.6", "@types/uuid": "^9.0.7", "@vitejs/plugin-react": "^4.2.0", "cors": "^2.8.5", diff --git a/src/components/Block.jsx b/src/components/Block.tsx similarity index 70% rename from src/components/Block.jsx rename to src/components/Block.tsx index d3a2bfff..d7fe3709 100644 --- a/src/components/Block.jsx +++ b/src/components/Block.tsx @@ -1,40 +1,43 @@ -import React from 'react' -import PropTypes from 'prop-types' +import React, {SyntheticEvent} from 'react' import classnames from 'classnames' import FieldDocLabel from './FieldDocLabel' import Doc from './Doc' +type BlockProps = { + "data-wd-key"?: string + label?: string + action?: React.ReactElement + style?: object + onChange?(...args: unknown[]): unknown + fieldSpec?: object + wideMode?: boolean + error?: unknown[] +}; + +type BlockState = { + showDoc: boolean +}; + /** Wrap a component with a label */ -export default class Block extends React.Component { - static propTypes = { - "data-wd-key": PropTypes.string, - label: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.element, - ]), - action: PropTypes.element, - children: PropTypes.node.isRequired, - style: PropTypes.object, - onChange: PropTypes.func, - fieldSpec: PropTypes.object, - wideMode: PropTypes.bool, - error: PropTypes.array, - } +export default class Block extends React.Component { + _blockEl: HTMLDivElement | null = null; - constructor (props) { + constructor (props: BlockProps) { super(props); this.state = { showDoc: false, } } - onChange(e) { + onChange(e: React.BaseSyntheticEvent) { const value = e.target.value - return this.props.onChange(value === "" ? undefined : value) + if (this.props.onChange) { + return this.props.onChange(value === "" ? undefined : value) + } } - onToggleDoc = (val) => { + onToggleDoc = (val: boolean) => { this.setState({ showDoc: val }); @@ -46,20 +49,17 @@ export default class Block extends React.Component { * causing the picker to reopen. This causes a scenario where the picker can * never be closed once open. */ - onLabelClick = (event) => { + onLabelClick = (event: SyntheticEvent) => { const el = event.nativeEvent.target; - const nativeEvent = event.nativeEvent; - const contains = this._blockEl.contains(el); + const contains = this._blockEl?.contains(el); if (event.nativeEvent.target.nodeName !== "INPUT" && !contains) { event.stopPropagation(); } - event.preventDefault(); + event.preventDefault(); } render() { - const errors = [].concat(this.props.error || []); - return