From 34cac7370c8d506d3cac2b65ceffbfe3e786f6b1 Mon Sep 17 00:00:00 2001
From: shira
Date: Tue, 16 May 2023 18:39:57 +0900
Subject: [PATCH] =?UTF-8?q?feat:=20FilterDropdown=20=E3=81=AB=20responseMe?=
=?UTF-8?q?ssage=20=E3=82=92=E6=B8=A1=E3=81=9B=E3=82=8B=E3=82=88=E3=81=86?=
=?UTF-8?q?=E3=81=AB=E3=81=99=E3=82=8B=20(#3348)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat: FilterDropdownにresponseMessageを渡せるようにする
* fix: Propsの渡し方を修正
* fix: responseMessageTypeの定義を共通のファイルに移動
* fix: story
* fix: 型名をUpperCamelCaseに修正
* fix: nestを減らして見通しを良くした
---
.../ActionDialog/ActionDialogContentInner.tsx | 13 +--
.../FilterDropdown/FilterDropdown.stories.tsx | 46 +++++++++-
.../FilterDropdown/FilterDropdown.tsx | 84 +++++++++++++------
src/types/props.ts | 9 ++
4 files changed, 114 insertions(+), 38 deletions(-)
diff --git a/src/components/Dialog/ActionDialog/ActionDialogContentInner.tsx b/src/components/Dialog/ActionDialog/ActionDialogContentInner.tsx
index 61e2f6e64f..85c1e2d8cd 100644
--- a/src/components/Dialog/ActionDialog/ActionDialogContentInner.tsx
+++ b/src/components/Dialog/ActionDialog/ActionDialogContentInner.tsx
@@ -2,7 +2,7 @@ import React, { FC, ReactNode, useCallback } from 'react'
import styled, { css } from 'styled-components'
import { Theme, useTheme } from '../../../hooks/useTheme'
-import { DecoratorsType } from '../../../types/props'
+import { DecoratorsType, ResponseMessageType } from '../../../types/props'
import { Button } from '../../Button'
import { HeadingTagTypes } from '../../Heading'
import { FaCheckCircleIcon, FaExclamationCircleIcon } from '../../Icon'
@@ -57,18 +57,9 @@ export type BaseProps = {
decorators?: DecoratorsType<'closeButtonLabel'>
}
-type responseMessageType =
- | {
- status: 'success' | 'error'
- text: ReactNode
- }
- | {
- status: 'processing'
- }
-
export type ActionDialogContentInnerProps = BaseProps & {
onClickClose: () => void
- responseMessage?: responseMessageType
+ responseMessage?: ResponseMessageType
titleId: string
}
diff --git a/src/components/Dropdown/FilterDropdown/FilterDropdown.stories.tsx b/src/components/Dropdown/FilterDropdown/FilterDropdown.stories.tsx
index d69bea0c58..1955638abd 100644
--- a/src/components/Dropdown/FilterDropdown/FilterDropdown.stories.tsx
+++ b/src/components/Dropdown/FilterDropdown/FilterDropdown.stories.tsx
@@ -1,11 +1,12 @@
import { action } from '@storybook/addon-actions'
import { Meta, StoryObj } from '@storybook/react'
-import React, { ReactNode, useCallback, useState } from 'react'
+import React, { ComponentProps, ReactNode, useCallback, useState } from 'react'
import styled from 'styled-components'
+import { Button } from '../../Button'
import { MultiComboBox, SingleComboBox } from '../../ComboBox'
import { Input } from '../../Input'
-import { Stack } from '../../Layout'
+import { Cluster, Stack } from '../../Layout'
import { RadioButton } from '../../RadioButton'
import { FilterDropdown } from './FilterDropdown'
@@ -30,6 +31,8 @@ const Render: React.FC = () => {
const [isFiltered2, setIsFiltered2] = React.useState(true)
const [isFiltered3, setIsFiltered3] = React.useState(true)
const [isFiltered4, setIsFiltered4] = React.useState(true)
+ const [responseMessage, setResponseMessage] =
+ useState['responseMessage']>()
return (
@@ -138,6 +141,45 @@ const Render: React.FC = () => {
+ Has response message
+
+ setIsFiltered4(true)}
+ onReset={() => setIsFiltered4(false)}
+ responseMessage={responseMessage}
+ >
+
+
+ You can change border text and color of the trigger button by setting `isFiltered`.
+
+ 切り替えボタン:
+
+
+
+
+
+
+
+
)
diff --git a/src/components/Dropdown/FilterDropdown/FilterDropdown.tsx b/src/components/Dropdown/FilterDropdown/FilterDropdown.tsx
index b83720a071..5346027544 100644
--- a/src/components/Dropdown/FilterDropdown/FilterDropdown.tsx
+++ b/src/components/Dropdown/FilterDropdown/FilterDropdown.tsx
@@ -3,10 +3,10 @@ import innerText from 'react-innertext'
import styled, { css } from 'styled-components'
import { Theme, useTheme } from '../../../hooks/useTheme'
-import { DecoratorType, DecoratorsType } from '../../../types/props'
+import { DecoratorType, DecoratorsType, ResponseMessageType } from '../../../types/props'
import { Button } from '../../Button'
-import { FaCheckCircleIcon, FaFilterIcon, FaUndoAltIcon } from '../../Icon'
-import { Cluster } from '../../Layout'
+import { FaCheckCircleIcon, FaExclamationCircleIcon, FaFilterIcon, FaUndoAltIcon } from '../../Icon'
+import { Cluster, Stack } from '../../Layout'
import { Dropdown } from '../Dropdown'
import { DropdownCloser } from '../DropdownCloser'
import { DropdownContent } from '../DropdownContent'
@@ -23,6 +23,7 @@ type Props = {
decorators?: DecoratorsType<
'status' | 'triggerButton' | 'applyButton' | 'cancelButton' | 'resetButton'
>
+ responseMessage?: ResponseMessageType
}
type ElementProps = Omit, keyof Props>
@@ -43,6 +44,7 @@ export const FilterDropdown: FC = ({
children,
hasStatusText,
decorators,
+ responseMessage,
...props
}: Props) => {
const themes = useTheme()
@@ -70,6 +72,8 @@ export const FilterDropdown: FC = ({
() => (hasStatusText ? undefined : innerText(status)),
[status, hasStatusText],
)
+ const isRequestProcessing =
+ responseMessage !== undefined && responseMessage.status === 'processing'
return (
@@ -93,25 +97,54 @@ export const FilterDropdown: FC = ({
{children}
-
- {onReset && (
-
- } onClick={onReset}>
- {resetButton}
-
-
+
+
+ {onReset && (
+
+ }
+ onClick={onReset}
+ disabled={isRequestProcessing}
+ >
+ {resetButton}
+
+
+ )}
+
+
+
+
+
+
+
+
+
+
+ {responseMessage?.status === 'success' && (
+
+
+
+ )}
+ {responseMessage?.status === 'error' && (
+
+
+
)}
-
-
-
-
-
-
-
-
-
+
)
@@ -139,10 +172,8 @@ const ContentLayout = styled.div<{ themes: Theme }>`
padding: ${space(1.5)};
`}
`
-const BottomLayout = styled(Cluster).attrs({ gap: 1, align: 'center', justify: 'space-between' })<{
- themes: Theme
-}>`
- ${({ themes: { border, space } }) => css`
+const ActionArea = styled(Stack).attrs({ gap: 0.5 })<{ themes: Theme }>`
+ ${({ themes: { space, border } }) => css`
border-block-start: ${border.shorthand};
padding: ${space(1)} ${space(1.5)};
`}
@@ -158,3 +189,6 @@ const RightButtonLayout = styled(Cluster).attrs({
})`
margin-inline-start: auto;
`
+const Message = styled.div`
+ text-align: right;
+`
diff --git a/src/types/props.ts b/src/types/props.ts
index 1988e3b4eb..cbafb2a54e 100644
--- a/src/types/props.ts
+++ b/src/types/props.ts
@@ -23,3 +23,12 @@ export type DecoratorsType = {
}
export type DecoratorType = (text: string) => ReactNode
+
+export type ResponseMessageType =
+ | {
+ status: 'success' | 'error'
+ text: ReactNode
+ }
+ | {
+ status: 'processing'
+ }