Skip to content

Commit

Permalink
feat(feedback): adding feedback and iconButtonToggle component
Browse files Browse the repository at this point in the history
  • Loading branch information
owilliams320 committed Aug 16, 2024
1 parent de014a6 commit 995ce8d
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Meta, StoryObj } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import Feedback from './index';

const meta = {
title: 'Components/Feedback',
component: Feedback,
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
parameters: {
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
layout: 'fullscreen',
},
args: {
label: 'Did this page help?',
labelForFeedback: 'Thank you for your feedback!',
onFeedBack: action('onFeedBack'),
}
} satisfies Meta<typeof Feedback>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Basic: Story = {};
51 changes: 51 additions & 0 deletions libs/react-components/src/lib/components/Feedback/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { useState } from 'react';
import styles from './styles.module.scss';
import IconButtonToggle from '../IconButtonToggle';
import Typography from '../Typography';

// Define the interface for the Feedback component props
interface FeedbackProps {
label?: string; // Optional label for the feedback component
labelForFeedback?: string; // Optional label to display after feedback is given
onFeedBack: (feedback: string) => void; // Callback function to handle feedback submission
}

const FeedbackComponent: React.FC<FeedbackProps> = ({
label = 'Did this page help?',
labelForFeedback = 'Thank you for your feedback!',
onFeedBack,
}) => {
const defaultFeedback = 'neutral';
const [feedback, setFeedback] = useState<string>(defaultFeedback);
const feedbackLabel = feedback !== defaultFeedback ? labelForFeedback : label;
const sendFeedback = (feedbackType: string) => {
const response = feedback === feedbackType ? defaultFeedback : feedbackType;
setFeedback(response);

if (onFeedBack) {
onFeedBack(response);
}
};

return (
<div className={styles.feedback}>
<span className={styles.feedbackLabel}>
<Typography scale="body1">{feedbackLabel}</Typography>
</span>
<IconButtonToggle
offIcon="thumb_up"
onIcon="thumb_up"
onClick={() => sendFeedback('positive')}
on={feedback === 'positive'}
/>
<IconButtonToggle
offIcon="thumb_down"
onIcon="thumb_down"
onClick={() => sendFeedback('negative')}
on={feedback === 'negative'}
/>
</div>
);
};

export default FeedbackComponent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.feedback {
display: flex;
min-height: 64px;
padding: 0px 16px 0px 24px;
align-items: center;
border-radius: 12px;
background-color: var(--cv-theme-surface-container-highest);
}

.feedbackLabel {
flex: 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Meta, StoryObj } from '@storybook/react';

import IconButtonToggle from './index';

const meta = {
title: 'Components/IconButtonToggle',
component: IconButtonToggle,
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
parameters: {
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
layout: 'fullscreen',
},
args: {
offIcon: 'home',
onIcon: 'houseboat',
},
} satisfies Meta<typeof IconButtonToggle>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Basic: Story = {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { CovalentIconButtonToggle } from '@covalent/components/icon-button-toggle';
import { createComponent } from '@lit/react';
import React from 'react';

interface IconButtonToggleProps {
/**
* Icon to be displayed in the button
*/
offIcon?: string;
/**
* Icon to be displayed in the button
*/
onIcon?: string;
/**
* Aria label for the icon button
*/
ariaLabel?: string;
/**
* Whether the button has any associated popup elements
*/
ariaHasPopup?: boolean;
/**
* Whether the icon button is disabled
*/
disabled?: boolean;
/**
* Click handler for the button
*/
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
}

const IconButtonToggleComponent = createComponent({
tagName: 'cv-icon-button-toggle',
elementClass: CovalentIconButtonToggle as never,
react: React,
});

const IconButtonToggle: React.FC<IconButtonToggleProps> = ({
offIcon,
onIcon,
ariaLabel,
ariaHasPopup,
disabled,
onClick,
}) => {
const customProps = {
offIcon,
onIcon,
disabled,
'aria-label': ariaLabel,
'aria-haspopup': ariaHasPopup,
onClick,
};
return <IconButtonToggleComponent {...customProps}></IconButtonToggleComponent>;
};

IconButtonToggle.displayName = 'IconButtonToggle';

export default IconButtonToggleComponent;

0 comments on commit 995ce8d

Please sign in to comment.