-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #403 from rebeccaalpert/quick-response-color
feat(QuickResponse): Add active and selected states
- Loading branch information
Showing
6 changed files
with
92 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/module/src/Message/QuickResponse/QuickResponse.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.pf-chatbot__message-quick-response { | ||
.pf-v6-c-label { | ||
--pf-v6-c-label--FontSize: var(--pf-t--global--font--size--md); | ||
|
||
@media screen and (min-width: 401px) and (max-width: 600px) { | ||
--pf-v6-c-label__text--MaxWidth: 20ch; | ||
} | ||
|
||
@media screen and (max-width: 400px) { | ||
--pf-v6-c-label__text--MaxWidth: 15ch; | ||
} | ||
} | ||
|
||
.pf-chatbot__message-quick-response--selected { | ||
.pf-v6-c-label__content:is(:hover, :focus) { | ||
--pf-v6-c-label--m-clickable--hover--BorderWidth: 0; | ||
--pf-v6-c-label--BackgroundColor: var(--pf-v6-c-label--m-blue--BackgroundColor); | ||
} | ||
} | ||
|
||
.pf-chatbot__message-quick-response--selected:hover, | ||
.pf-chatbot__message-quick-response--selected:focus { | ||
--pf-v6-c-label--m-clickable--hover--BorderWidth: 0; | ||
--pf-v6-c-label--BackgroundColor: var(--pf-v6-c-label--m-blue--BackgroundColor); | ||
} | ||
|
||
// active state right before selection | ||
.pf-v6-c-label.pf-m-blue.pf-m-clickable .pf-v6-c-label__content:is(:active) { | ||
--pf-v6-c-label--BackgroundColor: var(--pf-v6-c-label--m-blue--BackgroundColor); | ||
--pf-v6-c-label--m-clickable--hover--BackgroundColor: var(--pf-v6-c-label--m-blue--BackgroundColor); | ||
--pf-v6-c-label--m-clickable--hover--BorderWidth: 0; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/module/src/Message/QuickResponse/QuickResponse.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import { Label, LabelGroup, LabelGroupProps, LabelProps } from '@patternfly/react-core'; | ||
import { CheckIcon } from '@patternfly/react-icons'; | ||
|
||
export interface QuickResponse extends Omit<LabelProps, 'children'> { | ||
content: string; | ||
id: string; | ||
onClick: () => void; | ||
} | ||
|
||
export interface QuickResponseProps { | ||
/** Props for quick responses */ | ||
quickResponses: QuickResponse[]; | ||
/** Props for quick responses container */ | ||
quickResponseContainerProps?: Omit<LabelGroupProps, 'ref'>; | ||
} | ||
|
||
export const QuickResponse: React.FunctionComponent<QuickResponseProps> = ({ | ||
quickResponses, | ||
quickResponseContainerProps = { numLabels: 5 } | ||
}: QuickResponseProps) => { | ||
const [selectedQuickResponse, setSelectedQuickResponse] = React.useState<string>(); | ||
|
||
const handleQuickResponseClick = (id: string, onClick?: () => void) => { | ||
setSelectedQuickResponse(id); | ||
onClick && onClick(); | ||
}; | ||
return ( | ||
<LabelGroup | ||
className={`pf-chatbot__message-quick-response ${quickResponseContainerProps?.className}`} | ||
{...quickResponseContainerProps} | ||
> | ||
{quickResponses.map(({ id, onClick, content, className, ...props }: QuickResponse) => ( | ||
<Label | ||
variant={id === selectedQuickResponse ? undefined : 'outline'} | ||
icon={id === selectedQuickResponse ? <CheckIcon /> : undefined} | ||
color="blue" | ||
key={id} | ||
onClick={() => handleQuickResponseClick(id, onClick)} | ||
className={`${id === selectedQuickResponse ? 'pf-chatbot__message-quick-response--selected' : ''} ${className ? className : ''}`} | ||
{...props} | ||
> | ||
{content} | ||
</Label> | ||
))} | ||
</LabelGroup> | ||
); | ||
}; | ||
|
||
export default QuickResponse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters