Skip to content

Commit

Permalink
Primitives: Add types (#21482)
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham authored Apr 10, 2020
1 parent 3130e85 commit 319a8fc
Show file tree
Hide file tree
Showing 14 changed files with 1,071 additions and 984 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@storybook/addon-viewport": "5.3.2",
"@storybook/react": "5.3.2",
"@testing-library/react": "10.0.2",
"@types/classnames": "2.2.10",
"@types/lodash": "4.14.149",
"@types/prettier": "1.19.0",
"@types/qs": "6.9.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
type="button"
/>
<svg
aria-hidden="true"
aria-hidden={true}
fill="#000000"
focusable="false"
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
xmlns="http://www.w3.org/2000/svg"
>
<svg
aria-hidden="true"
aria-hidden={true}
fill="#000000"
focusable="false"
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ exports[`ColorPicker should commit changes to all views on blur 1`] = `
type="button"
>
<svg
aria-hidden="true"
focusable="false"
aria-hidden={true}
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down Expand Up @@ -329,8 +329,8 @@ exports[`ColorPicker should commit changes to all views on keyDown = DOWN 1`] =
type="button"
>
<svg
aria-hidden="true"
focusable="false"
aria-hidden={true}
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down Expand Up @@ -503,8 +503,8 @@ exports[`ColorPicker should commit changes to all views on keyDown = ENTER 1`] =
type="button"
>
<svg
aria-hidden="true"
focusable="false"
aria-hidden={true}
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down Expand Up @@ -677,8 +677,8 @@ exports[`ColorPicker should commit changes to all views on keyDown = UP 1`] = `
type="button"
>
<svg
aria-hidden="true"
focusable="false"
aria-hidden={true}
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down Expand Up @@ -851,8 +851,8 @@ exports[`ColorPicker should only update input view for draft changes 1`] = `
type="button"
>
<svg
aria-hidden="true"
focusable="false"
aria-hidden={true}
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down Expand Up @@ -1025,8 +1025,8 @@ exports[`ColorPicker should render color picker 1`] = `
type="button"
>
<svg
aria-hidden="true"
focusable="false"
aria-hidden={true}
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ exports[`MoreMenu should match snapshot 1`] = `
xmlns="http://www.w3.org/2000/svg"
>
<svg
aria-hidden="true"
focusable="false"
aria-hidden={true}
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ exports[`PluginMoreMenuItem renders menu item as button properly 1`] = `
type="button"
>
<svg
aria-hidden="true"
aria-hidden={true}
className="components-menu-items__item-icon"
focusable="false"
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ exports[`EnableCustomFieldsOption renders a checked checkbox and a confirmation
value="1"
/>
<svg
aria-hidden="true"
aria-hidden={true}
className="components-checkbox-control__checked"
focusable="false"
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down Expand Up @@ -80,9 +80,9 @@ exports[`EnableCustomFieldsOption renders a checked checkbox when custom fields
value="1"
/>
<svg
aria-hidden="true"
aria-hidden={true}
className="components-checkbox-control__checked"
focusable="false"
focusable={false}
height={24}
role="img"
viewBox="0 0 24 24"
Expand Down
4 changes: 4 additions & 0 deletions packages/primitives/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Master

Include TypeScript type declarations ([#21482](https://github.com/WordPress/gutenberg/pull/21482))

## 1.0.0

Initial release.
1 change: 1 addition & 0 deletions packages/primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"module": "build-module/index.js",
"react-native": "src/index",
"sideEffects": false,
"types": "build-types",
"dependencies": {
"@babel/runtime": "^7.9.2",
"@wordpress/element": "file:../element",
Expand Down
69 changes: 67 additions & 2 deletions packages/primitives/src/svg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,91 @@ import classnames from 'classnames';
*/
import { createElement } from '@wordpress/element';

// Disable reason: JSDoc linter doesn't seem to parse the union (`&`) correctly.
/* eslint-disable jsdoc/valid-types */
/** @typedef {{isPressed: boolean} & import('react').ComponentPropsWithoutRef<'svg'>} SVGProps */
/* eslint-enable jsdoc/valid-types */

/**
* @param {import('react').ComponentPropsWithoutRef<'circle'>} props
*
* @return {JSX.Element} Circle component
*/
export const Circle = ( props ) => createElement( 'circle', props );

/**
* @param {import('react').ComponentPropsWithoutRef<'g'>} props
*
* @return {JSX.Element} G component
*/
export const G = ( props ) => createElement( 'g', props );

/**
* @param {import('react').ComponentPropsWithoutRef<'path'>} props
*
* @return {JSX.Element} Path component
*/
export const Path = ( props ) => createElement( 'path', props );

/**
* @param {import('react').ComponentPropsWithoutRef<'polygon'>} props
*
* @return {JSX.Element} Polygon component
*/
export const Polygon = ( props ) => createElement( 'polygon', props );

/**
* @param {import('react').ComponentPropsWithoutRef<'rect'>} props
*
* @return {JSX.Element} Rect component
*/
export const Rect = ( props ) => createElement( 'rect', props );

/**
* @param {import('react').ComponentPropsWithoutRef<'defs'>} props
*
* @return {JSX.Element} Defs component
*/
export const Defs = ( props ) => createElement( 'defs', props );

/**
* @param {import('react').ComponentPropsWithoutRef<'radialGradient'>} props
*
* @return {JSX.Element} RadialGradient component
*/
export const RadialGradient = ( props ) =>
createElement( 'radialGradient', props );

/**
* @param {import('react').ComponentPropsWithoutRef<'linearGradient'>} props
*
* @return {JSX.Element} LinearGradient component
*/
export const LinearGradient = ( props ) =>
createElement( 'linearGradient', props );

/**
* @param {import('react').ComponentPropsWithoutRef<'stop'>} props
*
* @return {JSX.Element} Stop component
*/
export const Stop = ( props ) => createElement( 'stop', props );

/**
*
* @param {SVGProps} props isPressed indicates whether the SVG should appear as pressed.
* Other props will be passed through to svg component.
*
* @return {JSX.Element} Stop component
*/
export const SVG = ( { className, isPressed, ...props } ) => {
const appliedProps = {
...props,
className:
classnames( className, { 'is-pressed': isPressed } ) || undefined,
role: 'img',
'aria-hidden': 'true',
focusable: 'false',
'aria-hidden': true,
focusable: false,
};

// Disable reason: We need to have a way to render HTML tag for web.
Expand Down
9 changes: 9 additions & 0 deletions packages/primitives/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"include": [ "src/**/*" ],
"references": [ { "path": "../element" } ]
}
Loading

0 comments on commit 319a8fc

Please sign in to comment.