From e9eabff2a0962a4481218227f3f66af5c3de0147 Mon Sep 17 00:00:00 2001 From: Milan Brkic Date: Fri, 18 Oct 2019 12:34:25 +0200 Subject: [PATCH 01/12] RSP-1129: Tag and TagGroup component --- .../components/tags/index.css | 27 +++---- .../components/tags/skin.css | 64 +++++----------- .../spectrum-css-temp/vars/spectrum-dark.css | 4 +- .../vars/spectrum-darkest.css | 4 +- .../spectrum-css-temp/vars/spectrum-light.css | 6 +- .../vars/spectrum-lightest.css | 4 +- .../vars/spectrum-middark.css | 4 +- .../vars/spectrum-midlight.css | 4 +- packages/@react-aria/tag/index.ts | 1 + packages/@react-aria/tag/intl/cs-CZ.json | 3 + packages/@react-aria/tag/intl/da-DK.json | 3 + packages/@react-aria/tag/intl/de-DE.json | 3 + packages/@react-aria/tag/intl/en-US.json | 3 + packages/@react-aria/tag/intl/es-ES.json | 3 + packages/@react-aria/tag/intl/fi-FI.json | 3 + packages/@react-aria/tag/intl/fr-FR.json | 3 + packages/@react-aria/tag/intl/hu-HU.json | 3 + packages/@react-aria/tag/intl/it-IT.json | 3 + packages/@react-aria/tag/intl/ja-JP.json | 3 + packages/@react-aria/tag/intl/ko-KR.json | 3 + packages/@react-aria/tag/intl/nb-NO.json | 3 + packages/@react-aria/tag/intl/nl-NL.json | 3 + packages/@react-aria/tag/intl/pl-PL.json | 3 + packages/@react-aria/tag/intl/pt-BR.json | 3 + packages/@react-aria/tag/intl/ru-RU.json | 3 + packages/@react-aria/tag/intl/sv-SE.json | 3 + packages/@react-aria/tag/intl/tr-TR.json | 3 + packages/@react-aria/tag/intl/uk-UA.json | 3 + packages/@react-aria/tag/intl/zh-CN.json | 3 + packages/@react-aria/tag/intl/zh-TW.json | 3 + packages/@react-aria/tag/package.json | 30 ++++++++ packages/@react-aria/tag/src/index.ts | 2 + packages/@react-aria/tag/src/useTag.ts | 46 ++++++++++++ packages/@react-aria/tag/src/useTagGroup.ts | 25 +++++++ packages/@react-aria/tag/test/useTag.test.js | 19 +++++ .../button/src/ClearButton.tsx | 7 +- packages/@react-spectrum/tag/index.ts | 1 + packages/@react-spectrum/tag/package.json | 50 +++++++++++++ packages/@react-spectrum/tag/src/Tag.tsx | 74 +++++++++++++++++++ packages/@react-spectrum/tag/src/TagGroup.tsx | 72 ++++++++++++++++++ packages/@react-spectrum/tag/src/index.ts | 2 + .../tag/stories/Tag.stories.tsx | 67 +++++++++++++++++ .../tag/stories/TagGroup.stories.tsx | 31 ++++++++ packages/@react-spectrum/tag/test/Tag.test.js | 37 ++++++++++ packages/@react-types/shared/src/index.d.ts | 1 + .../@react-types/shared/src/removable.d.ts | 6 ++ packages/@react-types/tag/package.json | 16 ++++ packages/@react-types/tag/src/index.d.ts | 21 ++++++ 48 files changed, 618 insertions(+), 70 deletions(-) create mode 100644 packages/@react-aria/tag/index.ts create mode 100644 packages/@react-aria/tag/intl/cs-CZ.json create mode 100644 packages/@react-aria/tag/intl/da-DK.json create mode 100644 packages/@react-aria/tag/intl/de-DE.json create mode 100644 packages/@react-aria/tag/intl/en-US.json create mode 100644 packages/@react-aria/tag/intl/es-ES.json create mode 100644 packages/@react-aria/tag/intl/fi-FI.json create mode 100644 packages/@react-aria/tag/intl/fr-FR.json create mode 100644 packages/@react-aria/tag/intl/hu-HU.json create mode 100644 packages/@react-aria/tag/intl/it-IT.json create mode 100644 packages/@react-aria/tag/intl/ja-JP.json create mode 100644 packages/@react-aria/tag/intl/ko-KR.json create mode 100644 packages/@react-aria/tag/intl/nb-NO.json create mode 100644 packages/@react-aria/tag/intl/nl-NL.json create mode 100644 packages/@react-aria/tag/intl/pl-PL.json create mode 100644 packages/@react-aria/tag/intl/pt-BR.json create mode 100644 packages/@react-aria/tag/intl/ru-RU.json create mode 100644 packages/@react-aria/tag/intl/sv-SE.json create mode 100644 packages/@react-aria/tag/intl/tr-TR.json create mode 100644 packages/@react-aria/tag/intl/uk-UA.json create mode 100644 packages/@react-aria/tag/intl/zh-CN.json create mode 100644 packages/@react-aria/tag/intl/zh-TW.json create mode 100644 packages/@react-aria/tag/package.json create mode 100644 packages/@react-aria/tag/src/index.ts create mode 100644 packages/@react-aria/tag/src/useTag.ts create mode 100644 packages/@react-aria/tag/src/useTagGroup.ts create mode 100644 packages/@react-aria/tag/test/useTag.test.js create mode 100644 packages/@react-spectrum/tag/index.ts create mode 100644 packages/@react-spectrum/tag/package.json create mode 100644 packages/@react-spectrum/tag/src/Tag.tsx create mode 100644 packages/@react-spectrum/tag/src/TagGroup.tsx create mode 100644 packages/@react-spectrum/tag/src/index.ts create mode 100644 packages/@react-spectrum/tag/stories/Tag.stories.tsx create mode 100644 packages/@react-spectrum/tag/stories/TagGroup.stories.tsx create mode 100644 packages/@react-spectrum/tag/test/Tag.test.js create mode 100644 packages/@react-types/shared/src/removable.d.ts create mode 100644 packages/@react-types/tag/package.json create mode 100644 packages/@react-types/tag/src/index.d.ts diff --git a/packages/@adobe/spectrum-css-temp/components/tags/index.css b/packages/@adobe/spectrum-css-temp/components/tags/index.css index 59d73cafec3..d2784727cf0 100644 --- a/packages/@adobe/spectrum-css-temp/components/tags/index.css +++ b/packages/@adobe/spectrum-css-temp/components/tags/index.css @@ -41,8 +41,8 @@ governing permissions and limitations under the License. margin: calc(var(--spectrum-taggroup-tag-gap-y) / 2) calc(var(--spectrum-taggroup-tag-gap-x) / 2); padding: 0 calc(var(--spectrum-tag-padding-x) - var(--spectrum-tag-border-size)); - height: var(--spectrum-tag-height); - max-width: 100%; + block-size: var(--spectrum-tag-height); + max-inline-size: 100%; border-width: var(--spectrum-tag-border-size); border-style: solid; @@ -59,25 +59,22 @@ governing permissions and limitations under the License. pointer-events: none; } - > .spectrum-Icon, - > .spectrum-Avatar { - margin-right: var(--spectrum-tag-icon-padding-x); - - /* Add padding for "avatar" variant */ - margin-left: calc(var(--spectrum-tag-avatar-padding-x) - var(--spectrum-tag-padding-x)); - - ~ .spectrum-Tags-itemLabel { - margin-right: calc(var(--spectrum-tag-avatar-padding-x) - var(--spectrum-tag-padding-x)); - } + > .spectrum-Tags-itemIcon { + margin-inline-end: var(--spectrum-tag-icon-padding-x); + margin-inline-start: calc(-1 * var(--spectrum-tag-deletable-border-size-key-focus)); } - .spectrum-ClearButton { - margin-right: calc(-1 * var(--spectrum-tag-padding-x)); + > .spectrum-Tags-item-ClearButton { + margin-inline-end: calc(-0.5 * var(--spectrum-tag-padding-x)); + margin-inline-start: var(--spectrum-tag-deletable-border-size-key-focus); + block-size: var(--spectrum-alias-font-size-default); + inline-size: var(--spectrum-alias-font-size-default); + border-radius: var(--spectrum-alias-border-radius-small); } } .spectrum-Tags-itemLabel { - height: 100%; + block-size: 100%; line-height: calc(var(--spectrum-tag-height) - calc(var(--spectrum-tag-border-size) * 2)); flex: 1 1 auto; font-size: var(--spectrum-tag-text-size); diff --git a/packages/@adobe/spectrum-css-temp/components/tags/skin.css b/packages/@adobe/spectrum-css-temp/components/tags/skin.css index 43920b66ade..b77a9f5895b 100644 --- a/packages/@adobe/spectrum-css-temp/components/tags/skin.css +++ b/packages/@adobe/spectrum-css-temp/components/tags/skin.css @@ -15,18 +15,10 @@ governing permissions and limitations under the License. background-color: var(--spectrum-tag-background-color); border-color: var(--spectrum-tag-border-color); - .spectrum-ClearButton { - color: var(--spectrum-tag-deletable-icon-color); - } - &:hover { background-color: var(--spectrum-tag-background-color-hover); color: var(--spectrum-tag-text-color-hover); border-color: var(--spectrum-tag-border-color-hover); - - .spectrum-ClearButton { - color: var(--spectrum-tag-deletable-icon-color-hover); - } } &:focus-ring { @@ -34,38 +26,34 @@ governing permissions and limitations under the License. color: var(--spectrum-tag-text-color-key-focus); border-color: var(--spectrum-tag-border-color-key-focus); box-shadow: 0 0 0 1px var(--spectrum-tag-border-color-key-focus); - - .spectrum-ClearButton { - color: var(--spectrum-tag-deletable-icon-color-key-focus); - } } &.is-invalid { color: var(--spectrum-tag-text-color-error); border-color: var(--spectrum-tag-border-color-error); - .spectrum-ClearButton { - color: var(--spectrum-tag-icon-color-error); - } - &:hover { color: var(--spectrum-tag-text-color-error-hover); border-color: var(--spectrum-tag-border-color-error-hover); - - .spectrum-ClearButton { - color: var(--spectrum-tag-icon-color-error-hover); - } } &:focus-ring { color: var(--spectrum-tag-text-color-error-key-focus); border-color: var(--spectrum-tag-border-color-key-focus); box-shadow: 0 0 0 1px var(--spectrum-tag-border-color-key-focus); + } - .spectrum-ClearButton { - color: var(--spectrum-tag-icon-color-error-key-focus); + .spectrum-Tags-itemLabel { + color: var(--spectrum-tag-text-color-error); + } + .spectrum-Tags-itemIcon, + .spectrum-Tags-item-ClearButton { + color: var(--spectrum-tag-border-color-error); + &.clearButton-focus { + color: white; } } + } &.is-disabled { @@ -83,55 +71,39 @@ governing permissions and limitations under the License. .spectrum-Tags-item--deletable { &:hover { color: var(--spectrum-tag-deletable-text-color-hover); - - .spectrum-ClearButton { - color: var(--spectrum-tag-deletable-icon-color-hover); - } } &:active { color: var(--spectrum-tag-deletable-text-color-down); - - .spectrum-ClearButton { - color: var(--spectrum-tag-deletable-icon-color-down); - } } &.is-invalid { &:hover { border-color: var(--spectrum-tag-deletable-border-color-error-hover); color: var(--spectrum-tag-deletable-text-color-error-hover); - - .spectrum-ClearButton { - color: var(--spectrum-tag-deletable-icon-color-error-hover); - } } &:active { border-color: var(--spectrum-tag-deletable-border-color-error-down); color: var(--spectrum-tag-deletable-text-color-error-down); - - .spectrum-ClearButton { - color: var(--spectrum-tag-deletable-icon-color-error-down); - } } } &:focus-ring { color: var(--spectrum-tag-deletable-text-color-key-focus); - .spectrum-ClearButton { - color: var(--spectrum-tag-deletable-icon-color-key-focus); - } - &.is-invalid { color: var(--spectrum-tag-deletable-text-color-error-key-focus); } } -} -.spectrum-Tags-item.is-disabled .spectrum-ClearButton { - .spectrum-Icon { - color: var(--spectrum-tag-icon-color-disabled); + > .spectrum-Tags-item-ClearButton { + &.clearButton-focus { + background-color: var(--spectrum-tag-deletable-background-color-focus); + color: white; + } + &:hover { + background-color: var(--spectrum-global-color-gray-300) + } } } diff --git a/packages/@adobe/spectrum-css-temp/vars/spectrum-dark.css b/packages/@adobe/spectrum-css-temp/vars/spectrum-dark.css index fbc12b79135..f6bbab63f2f 100644 --- a/packages/@adobe/spectrum-css-temp/vars/spectrum-dark.css +++ b/packages/@adobe/spectrum-css-temp/vars/spectrum-dark.css @@ -2307,7 +2307,7 @@ --spectrum-tag-icon-color-disabled: rgb(110, 110, 110); --spectrum-tag-border-color-error: rgb(236, 91, 98); --spectrum-tag-icon-color-error: rgb(236, 91, 98); - --spectrum-tag-text-color-error: rgb(185, 185, 185); + --spectrum-tag-text-color-error: rgb(247, 109, 116); --spectrum-tag-border-color-error-hover: rgb(247, 109, 116); --spectrum-tag-icon-color-error-hover: rgb(247, 109, 116); --spectrum-tag-text-color-error-hover: rgb(255, 255, 255); @@ -2330,6 +2330,8 @@ --spectrum-tag-deletable-text-color-down: rgb(185, 185, 185); --spectrum-tag-deletable-icon-color-down: rgb(255, 255, 255); --spectrum-tag-deletable-background-color-key-focus: rgb(47, 47, 47); + --spectrum-tag-deletable-color-focus: rgb(255, 255, 255); + --spectrum-tag-deletable-background-color-focus: rgb(38, 128, 235); --spectrum-tag-deletable-border-color-key-focus: rgb(38, 128, 235); --spectrum-tag-deletable-text-color-key-focus: rgb(185, 185, 185); --spectrum-tag-deletable-icon-color-key-focus: rgb(255, 255, 255); diff --git a/packages/@adobe/spectrum-css-temp/vars/spectrum-darkest.css b/packages/@adobe/spectrum-css-temp/vars/spectrum-darkest.css index e0dcf737c40..957f49847a6 100644 --- a/packages/@adobe/spectrum-css-temp/vars/spectrum-darkest.css +++ b/packages/@adobe/spectrum-css-temp/vars/spectrum-darkest.css @@ -2307,7 +2307,7 @@ --spectrum-tag-icon-color-disabled: rgb(92, 92, 92); --spectrum-tag-border-color-error: rgb(227, 72, 80); --spectrum-tag-icon-color-error: rgb(227, 72, 80); - --spectrum-tag-text-color-error: rgb(162, 162, 162); + --spectrum-tag-text-color-error: rgb(236, 91, 98); --spectrum-tag-border-color-error-hover: rgb(236, 91, 98); --spectrum-tag-icon-color-error-hover: rgb(236, 91, 98); --spectrum-tag-text-color-error-hover: rgb(239, 239, 239); @@ -2330,6 +2330,8 @@ --spectrum-tag-deletable-text-color-down: rgb(162, 162, 162); --spectrum-tag-deletable-icon-color-down: rgb(239, 239, 239); --spectrum-tag-deletable-background-color-key-focus: rgb(26, 26, 26); + --spectrum-tag-deletable-color-focus: rgb(239, 239, 239); + --spectrum-tag-deletable-background-color-focus: rgb(20, 115, 230); --spectrum-tag-deletable-border-color-key-focus: rgb(20, 115, 230); --spectrum-tag-deletable-text-color-key-focus: rgb(162, 162, 162); --spectrum-tag-deletable-icon-color-key-focus: rgb(239, 239, 239); diff --git a/packages/@adobe/spectrum-css-temp/vars/spectrum-light.css b/packages/@adobe/spectrum-css-temp/vars/spectrum-light.css index b4fd874f9d2..f2a82183323 100644 --- a/packages/@adobe/spectrum-css-temp/vars/spectrum-light.css +++ b/packages/@adobe/spectrum-css-temp/vars/spectrum-light.css @@ -2307,7 +2307,7 @@ --spectrum-tag-icon-color-disabled: rgb(179, 179, 179); --spectrum-tag-border-color-error: rgb(215, 55, 63); --spectrum-tag-icon-color-error: rgb(215, 55, 63); - --spectrum-tag-text-color-error: rgb(110, 110, 110); + --spectrum-tag-text-color-error: rgb(201, 37, 45); --spectrum-tag-border-color-error-hover: rgb(201, 37, 45); --spectrum-tag-icon-color-error-hover: rgb(201, 37, 45); --spectrum-tag-text-color-error-hover: rgb(44, 44, 44); @@ -2323,7 +2323,7 @@ --spectrum-tag-deletable-icon-color: rgb(142, 142, 142); --spectrum-tag-deletable-background-color-hover: rgb(250, 250, 250); --spectrum-tag-deletable-border-color-hover: rgb(44, 44, 44); - --spectrum-tag-deletable-text-color-hover: rgb(110, 110, 110); + --spectrum-tag-deletable-text-color-hover: rgb(44, 44, 44); --spectrum-tag-deletable-icon-color-hover: rgb(44, 44, 44); --spectrum-tag-deletable-background-color-down: rgb(250, 250, 250); --spectrum-tag-deletable-border-color-down: rgb(44, 44, 44); @@ -2331,6 +2331,8 @@ --spectrum-tag-deletable-icon-color-down: rgb(44, 44, 44); --spectrum-tag-deletable-background-color-key-focus: rgb(250, 250, 250); --spectrum-tag-deletable-border-color-key-focus: rgb(38, 128, 235); + --spectrum-tag-deletable-color-focus: rgb(255, 255, 255); + --spectrum-tag-deletable-background-color-focus: rgb(38, 128, 235); --spectrum-tag-deletable-text-color-key-focus: rgb(110, 110, 110); --spectrum-tag-deletable-icon-color-key-focus: rgb(44, 44, 44); --spectrum-tag-deletable-background-color-disabled: rgb(234, 234, 234); diff --git a/packages/@adobe/spectrum-css-temp/vars/spectrum-lightest.css b/packages/@adobe/spectrum-css-temp/vars/spectrum-lightest.css index a6ef6bdd50b..54d50dd2296 100644 --- a/packages/@adobe/spectrum-css-temp/vars/spectrum-lightest.css +++ b/packages/@adobe/spectrum-css-temp/vars/spectrum-lightest.css @@ -2307,7 +2307,7 @@ --spectrum-tag-icon-color-disabled: rgb(188, 188, 188); --spectrum-tag-border-color-error: rgb(227, 72, 80); --spectrum-tag-icon-color-error: rgb(227, 72, 80); - --spectrum-tag-text-color-error: rgb(116, 116, 116); + --spectrum-tag-text-color-error: rgb(215, 55, 63); --spectrum-tag-border-color-error-hover: rgb(215, 55, 63); --spectrum-tag-icon-color-error-hover: rgb(215, 55, 63); --spectrum-tag-text-color-error-hover: rgb(50, 50, 50); @@ -2330,6 +2330,8 @@ --spectrum-tag-deletable-text-color-down: rgb(116, 116, 116); --spectrum-tag-deletable-icon-color-down: rgb(50, 50, 50); --spectrum-tag-deletable-background-color-key-focus: rgb(255, 255, 255); + --spectrum-tag-deletable-color-focus: rgb(255, 255, 255); + --spectrum-tag-deletable-background-color-focus: rgb(55, 142, 240); --spectrum-tag-deletable-border-color-key-focus: rgb(55, 142, 240); --spectrum-tag-deletable-text-color-key-focus: rgb(116, 116, 116); --spectrum-tag-deletable-icon-color-key-focus: rgb(50, 50, 50); diff --git a/packages/@adobe/spectrum-css-temp/vars/spectrum-middark.css b/packages/@adobe/spectrum-css-temp/vars/spectrum-middark.css index 2dd83ca84ca..1f7d82f7704 100644 --- a/packages/@adobe/spectrum-css-temp/vars/spectrum-middark.css +++ b/packages/@adobe/spectrum-css-temp/vars/spectrum-middark.css @@ -2307,7 +2307,7 @@ --spectrum-tag-icon-color-disabled: rgb(118, 118, 118); --spectrum-tag-border-color-error: rgb(247, 109, 116); --spectrum-tag-icon-color-error: rgb(247, 109, 116); - --spectrum-tag-text-color-error: rgb(186, 186, 186); + --spectrum-tag-text-color-error: rgb(255, 123, 130); --spectrum-tag-border-color-error-hover: rgb(255, 123, 130); --spectrum-tag-icon-color-error-hover: rgb(255, 123, 130); --spectrum-tag-text-color-error-hover: rgb(255, 255, 255); @@ -2330,6 +2330,8 @@ --spectrum-tag-deletable-text-color-down: rgb(186, 186, 186); --spectrum-tag-deletable-icon-color-down: rgb(255, 255, 255); --spectrum-tag-deletable-background-color-key-focus: rgb(71, 71, 71); + --spectrum-tag-deletable-color-focus: rgb(255, 255, 255); + --spectrum-tag-deletable-background-color-focus: rgb(55, 142, 240); --spectrum-tag-deletable-border-color-key-focus: rgb(55, 142, 240); --spectrum-tag-deletable-text-color-key-focus: rgb(186, 186, 186); --spectrum-tag-deletable-icon-color-key-focus: rgb(255, 255, 255); diff --git a/packages/@adobe/spectrum-css-temp/vars/spectrum-midlight.css b/packages/@adobe/spectrum-css-temp/vars/spectrum-midlight.css index 129a29c7ad4..0ad798f5ec6 100644 --- a/packages/@adobe/spectrum-css-temp/vars/spectrum-midlight.css +++ b/packages/@adobe/spectrum-css-temp/vars/spectrum-midlight.css @@ -2307,7 +2307,7 @@ --spectrum-tag-icon-color-disabled: rgb(160, 160, 160); --spectrum-tag-border-color-error: rgb(201, 37, 45); --spectrum-tag-icon-color-error: rgb(201, 37, 45); - --spectrum-tag-text-color-error: rgb(97, 97, 97); + --spectrum-tag-text-color-error: rgb(187, 18, 26); --spectrum-tag-border-color-error-hover: rgb(187, 18, 26); --spectrum-tag-icon-color-error-hover: rgb(187, 18, 26); --spectrum-tag-text-color-error-hover: rgb(25, 25, 25); @@ -2330,6 +2330,8 @@ --spectrum-tag-deletable-text-color-down: rgb(97, 97, 97); --spectrum-tag-deletable-icon-color-down: rgb(25, 25, 25); --spectrum-tag-deletable-background-color-key-focus: rgb(228, 228, 228); + --spectrum-tag-deletable-color-focus: rgb(255, 255, 255); + --spectrum-tag-deletable-background-color-focus: rgb(20, 115, 230); --spectrum-tag-deletable-border-color-key-focus: rgb(20, 115, 230); --spectrum-tag-deletable-text-color-key-focus: rgb(97, 97, 97); --spectrum-tag-deletable-icon-color-key-focus: rgb(25, 25, 25); diff --git a/packages/@react-aria/tag/index.ts b/packages/@react-aria/tag/index.ts new file mode 100644 index 00000000000..8420b1093fd --- /dev/null +++ b/packages/@react-aria/tag/index.ts @@ -0,0 +1 @@ +export * from './src'; diff --git a/packages/@react-aria/tag/intl/cs-CZ.json b/packages/@react-aria/tag/intl/cs-CZ.json new file mode 100644 index 00000000000..2aa8bd22e0d --- /dev/null +++ b/packages/@react-aria/tag/intl/cs-CZ.json @@ -0,0 +1,3 @@ +{ + "Remove": "Odebrat" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/da-DK.json b/packages/@react-aria/tag/intl/da-DK.json new file mode 100644 index 00000000000..8e7b4c569fe --- /dev/null +++ b/packages/@react-aria/tag/intl/da-DK.json @@ -0,0 +1,3 @@ +{ + "Remove": "Fjern" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/de-DE.json b/packages/@react-aria/tag/intl/de-DE.json new file mode 100644 index 00000000000..adb1d2ed5d6 --- /dev/null +++ b/packages/@react-aria/tag/intl/de-DE.json @@ -0,0 +1,3 @@ +{ + "Remove": "Entfernen" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/en-US.json b/packages/@react-aria/tag/intl/en-US.json new file mode 100644 index 00000000000..67ff0e1312a --- /dev/null +++ b/packages/@react-aria/tag/intl/en-US.json @@ -0,0 +1,3 @@ +{ + "remove": "Remove" +} diff --git a/packages/@react-aria/tag/intl/es-ES.json b/packages/@react-aria/tag/intl/es-ES.json new file mode 100644 index 00000000000..7ec4fc35115 --- /dev/null +++ b/packages/@react-aria/tag/intl/es-ES.json @@ -0,0 +1,3 @@ +{ + "Remove": "Quitar" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/fi-FI.json b/packages/@react-aria/tag/intl/fi-FI.json new file mode 100644 index 00000000000..7373cc76a68 --- /dev/null +++ b/packages/@react-aria/tag/intl/fi-FI.json @@ -0,0 +1,3 @@ +{ + "Remove": "Poista" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/fr-FR.json b/packages/@react-aria/tag/intl/fr-FR.json new file mode 100644 index 00000000000..f8e24efa4b0 --- /dev/null +++ b/packages/@react-aria/tag/intl/fr-FR.json @@ -0,0 +1,3 @@ +{ + "Remove": "Supprimer" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/hu-HU.json b/packages/@react-aria/tag/intl/hu-HU.json new file mode 100644 index 00000000000..0ecb8992cca --- /dev/null +++ b/packages/@react-aria/tag/intl/hu-HU.json @@ -0,0 +1,3 @@ +{ + "Remove": "Eltávolítás" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/it-IT.json b/packages/@react-aria/tag/intl/it-IT.json new file mode 100644 index 00000000000..a3a21047fe9 --- /dev/null +++ b/packages/@react-aria/tag/intl/it-IT.json @@ -0,0 +1,3 @@ +{ + "Remove": "Rimuovi" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/ja-JP.json b/packages/@react-aria/tag/intl/ja-JP.json new file mode 100644 index 00000000000..54893071fe0 --- /dev/null +++ b/packages/@react-aria/tag/intl/ja-JP.json @@ -0,0 +1,3 @@ +{ + "Remove": "削除" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/ko-KR.json b/packages/@react-aria/tag/intl/ko-KR.json new file mode 100644 index 00000000000..1b983b3a827 --- /dev/null +++ b/packages/@react-aria/tag/intl/ko-KR.json @@ -0,0 +1,3 @@ +{ + "Remove": "제거" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/nb-NO.json b/packages/@react-aria/tag/intl/nb-NO.json new file mode 100644 index 00000000000..8e7b4c569fe --- /dev/null +++ b/packages/@react-aria/tag/intl/nb-NO.json @@ -0,0 +1,3 @@ +{ + "Remove": "Fjern" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/nl-NL.json b/packages/@react-aria/tag/intl/nl-NL.json new file mode 100644 index 00000000000..f53d4522b0a --- /dev/null +++ b/packages/@react-aria/tag/intl/nl-NL.json @@ -0,0 +1,3 @@ +{ + "Remove": "Verwijderen" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/pl-PL.json b/packages/@react-aria/tag/intl/pl-PL.json new file mode 100644 index 00000000000..caab1655e4c --- /dev/null +++ b/packages/@react-aria/tag/intl/pl-PL.json @@ -0,0 +1,3 @@ +{ + "Remove": "Usuń" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/pt-BR.json b/packages/@react-aria/tag/intl/pt-BR.json new file mode 100644 index 00000000000..7fcaa36880f --- /dev/null +++ b/packages/@react-aria/tag/intl/pt-BR.json @@ -0,0 +1,3 @@ +{ + "Remove": "Remover" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/ru-RU.json b/packages/@react-aria/tag/intl/ru-RU.json new file mode 100644 index 00000000000..e638e251b04 --- /dev/null +++ b/packages/@react-aria/tag/intl/ru-RU.json @@ -0,0 +1,3 @@ +{ + "Remove": "Удалить" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/sv-SE.json b/packages/@react-aria/tag/intl/sv-SE.json new file mode 100644 index 00000000000..b840bda6e5c --- /dev/null +++ b/packages/@react-aria/tag/intl/sv-SE.json @@ -0,0 +1,3 @@ +{ + "Remove": "Ta bort" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/tr-TR.json b/packages/@react-aria/tag/intl/tr-TR.json new file mode 100644 index 00000000000..703759e92c6 --- /dev/null +++ b/packages/@react-aria/tag/intl/tr-TR.json @@ -0,0 +1,3 @@ +{ + "Remove": "Kaldır" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/uk-UA.json b/packages/@react-aria/tag/intl/uk-UA.json new file mode 100644 index 00000000000..683c9e259ab --- /dev/null +++ b/packages/@react-aria/tag/intl/uk-UA.json @@ -0,0 +1,3 @@ +{ + "Remove": "Видалити" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/zh-CN.json b/packages/@react-aria/tag/intl/zh-CN.json new file mode 100644 index 00000000000..061e5350ab0 --- /dev/null +++ b/packages/@react-aria/tag/intl/zh-CN.json @@ -0,0 +1,3 @@ +{ + "Remove": "删除" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/intl/zh-TW.json b/packages/@react-aria/tag/intl/zh-TW.json new file mode 100644 index 00000000000..a2417e60ddd --- /dev/null +++ b/packages/@react-aria/tag/intl/zh-TW.json @@ -0,0 +1,3 @@ +{ + "Remove": "移除" +} \ No newline at end of file diff --git a/packages/@react-aria/tag/package.json b/packages/@react-aria/tag/package.json new file mode 100644 index 00000000000..939d6a08c89 --- /dev/null +++ b/packages/@react-aria/tag/package.json @@ -0,0 +1,30 @@ +{ + "name": "@react-aria/tag", + "version": "3.0.0-alpha.1", + "description": "Spectrum UI components in React", + "main": "dist/main.js", + "module": "dist/module.js", + "types": "dist/types.d.ts", + "source": "src/index.ts", + "files": [ + "dist" + ], + "sideEffects": false, + "repository": { + "type": "git", + "url": "https://github.com/adobe/react-spectrum" + }, + "dependencies": { + "@babel/runtime": "^7.6.2", + "@react-aria/i18n": "^3.0.0-alpha.1", + "@react-aria/utils": "^3.0.0-alpha.1", + "@react-types/shared": "^3.0.0-alpha.1", + "@react-types/tag": "^3.0.0-alpha.1" + }, + "peerDependencies": { + "react": "^16.8.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/@react-aria/tag/src/index.ts b/packages/@react-aria/tag/src/index.ts new file mode 100644 index 00000000000..e7f45f3726a --- /dev/null +++ b/packages/@react-aria/tag/src/index.ts @@ -0,0 +1,2 @@ +export * from './useTag'; +export * from './useTagGroup'; diff --git a/packages/@react-aria/tag/src/useTag.ts b/packages/@react-aria/tag/src/useTag.ts new file mode 100644 index 00000000000..9d51981686c --- /dev/null +++ b/packages/@react-aria/tag/src/useTag.ts @@ -0,0 +1,46 @@ +import {AriaTagProps} from '@react-types/tag'; +import {ButtonHTMLAttributes, HTMLAttributes, KeyboardEvent} from 'react'; +import intlMessages from '../intl/*.json'; +import {mergeProps} from '@react-aria/utils'; +import {useMessageFormatter} from '@react-aria/i18n'; + +interface TagAria { + tagProps: HTMLAttributes, + clearButtonProps: ButtonHTMLAttributes +} + +export function useTag(props: AriaTagProps): TagAria { + const { + isRemovable, + isDisabled, + onRemove, + children, + selected, + role + } = props; + const formatMessage = useMessageFormatter(intlMessages); + const removeString = formatMessage('remove'); + + function onKeyDown(e: KeyboardEvent) { + if (e.key === 'Delete' || e.key === 'Backspace') { + onRemove(children, e); + e.preventDefault(); + } + } + const pressProps = { + onPress: e => onRemove(children, e) + }; + return { + tagProps: { + 'aria-selected': role === 'gridcell' ? undefined : !isDisabled && selected, + onKeyDown: !isDisabled && isRemovable ? onKeyDown : null, + role, + tabIndex: isDisabled ? -1 : 0 + }, + clearButtonProps: mergeProps(pressProps, { + 'aria-label': children ? `${removeString}: ${children}` : removeString, + title: removeString, + isDisabled + }) + }; +} diff --git a/packages/@react-aria/tag/src/useTagGroup.ts b/packages/@react-aria/tag/src/useTagGroup.ts new file mode 100644 index 00000000000..d5470751d54 --- /dev/null +++ b/packages/@react-aria/tag/src/useTagGroup.ts @@ -0,0 +1,25 @@ +import {DOMProps, MultipleSelectionBase} from '@react-types/shared'; + +interface AriaTagGroupProps extends MultipleSelectionBase { + isDisabled?: boolean, + isReadOnly?: boolean, // removes close button + validationState?: 'valid' | 'invalid' +} + +interface TagGroupAria { + tagGroupProps: DOMProps +} + +export function useTagGroup(props: AriaTagGroupProps): TagGroupAria { + const {isDisabled, validationState} = props; + return { + tagGroupProps: { + role: 'grid', + 'aria-atomic': false, + 'aria-relevant': 'additions', + // 'aria-live': focused ? 'polite' : 'off', + 'aria-disabled': isDisabled, + 'aria-invalid': validationState === 'invalid' + } + }; +} diff --git a/packages/@react-aria/tag/test/useTag.test.js b/packages/@react-aria/tag/test/useTag.test.js new file mode 100644 index 00000000000..585d914eba7 --- /dev/null +++ b/packages/@react-aria/tag/test/useTag.test.js @@ -0,0 +1,19 @@ +import {renderHook} from 'react-hooks-testing-library'; +import {useTag} from '../'; + +describe('useTag tests', () => { + it('handles defaults', () => { + let props = {}; + let {result} = renderHook(() => useTag(props)); + expect(result.current.tagProps.onKeyDown).toBeDefined(); + expect(result.current.clearButtonProps.onPress).toBeDefined(); + }); + + it('handles disabled flag', () => { + let props = {isDisabled: true}; + let {result} = renderHook(() => useTag(props)); + expect(result.current.tagProps.onKeyDown).toBe(null); + expect(result.current.tagProps.tabIndex).toBe(-1); + expect(result.current.clearButtonProps.isDisabled).toBe(true); + }); +}); diff --git a/packages/@react-spectrum/button/src/ClearButton.tsx b/packages/@react-spectrum/button/src/ClearButton.tsx index f84664061ee..7aed638bbba 100644 --- a/packages/@react-spectrum/button/src/ClearButton.tsx +++ b/packages/@react-spectrum/button/src/ClearButton.tsx @@ -6,18 +6,21 @@ import React, {RefObject, useRef} from 'react'; import styles from '@adobe/spectrum-css-temp/components/button/vars.css'; import {useButton} from '@react-aria/button'; -interface ClearButtonProps extends ButtonBase {} +interface ClearButtonProps extends ButtonBase { + focusClassName?: string, +} export const ClearButton = React.forwardRef((props: ClearButtonProps, ref: RefObject) => { let { className, + focusClassName, ...otherProps } = props; ref = ref || useRef(); let {buttonProps, isPressed} = useButton({...props, ref}); return ( - +