-
Notifications
You must be signed in to change notification settings - Fork 2
A few minor component updates. #605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,152 @@ | ||
| import React from "react"; | ||
| import Action, { ActionProps } from "./Action"; | ||
| import Layout from "../Layout"; | ||
| import React from 'react'; | ||
| import Action, { ActionProps } from './Action'; | ||
| import Layout from '../Layout'; | ||
| import './Action.stories.css'; | ||
| import { FontAwesomeSvgIcon } from "react-fontawesome-svg-icon"; | ||
| import { faFile } from "@fortawesome/free-solid-svg-icons"; | ||
| import { Meta, StoryObj } from "@storybook/react"; | ||
| import { FontAwesomeSvgIcon } from 'react-fontawesome-svg-icon'; | ||
| import { faArrowRight, faFile, faHeart } from '@fortawesome/free-solid-svg-icons'; | ||
| import { Meta, StoryObj } from '@storybook/react'; | ||
| import { argTypesToHide } from '../../../../.storybook/helpers'; | ||
|
|
||
| const meta: Meta<typeof Action> = { | ||
| title: "Presentational/Action", | ||
| component: Action, | ||
| parameters: { | ||
| layout: 'fullscreen' | ||
| } | ||
| type ActionStoryArgs = React.ComponentProps<typeof Action> & { | ||
| colorScheme: 'auto' | 'light' | 'dark'; | ||
| withClass: boolean; | ||
| withIcon: boolean; | ||
| withTitleIcon: boolean; | ||
| withIndicator: boolean; | ||
| withIndicatorIcon: boolean; | ||
| withIndicatorValue: boolean; | ||
| withClickHandler: boolean; | ||
| parentCursor: 'not set' | 'pointer' | 'crosshair'; | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof Action>; | ||
|
|
||
| const render = (args: ActionProps) => | ||
| <Layout colorScheme="auto"> | ||
| <Action {...args} /> | ||
| </Layout>; | ||
| const meta: Meta<ActionStoryArgs> = { | ||
| title: 'Presentational/Action', | ||
| component: Action, | ||
| parameters: { | ||
| layout: 'fullscreen' | ||
| }, | ||
| render: (storyArgs: ActionStoryArgs) => { | ||
| const componentArgs: ActionProps = { | ||
| ...storyArgs, | ||
| ...(storyArgs.withClass && { className: 'action-story-primary', renderAs: 'div' }), | ||
| ...(storyArgs.withIcon && { icon: <FontAwesomeSvgIcon icon={faFile} color="#2e6e9e" /> }), | ||
| ...(storyArgs.withTitleIcon && { titleIcon: <FontAwesomeSvgIcon icon={faHeart} color="#df4747" style={{ marginRight: '4px' }} /> }), | ||
| ...(storyArgs.withIndicator && { indicator: <FontAwesomeSvgIcon icon={faArrowRight} color="#2e6e9e" /> }), | ||
| ...(storyArgs.withIndicatorIcon && { indicatorIcon: faArrowRight }), | ||
| ...(storyArgs.withIndicatorValue && { indicatorValue: '3' }), | ||
| ...(storyArgs.withClickHandler && { onClick: () => alert('Clicked') }) | ||
| }; | ||
|
|
||
| const baseArgs : ActionProps = { | ||
| title: "Baseline Survey", | ||
| subtitle: "Tap here to start your baseline survey", | ||
| onClick: () => alert("Clicked") | ||
| return <Layout colorScheme={storyArgs.colorScheme}> | ||
| <div style={{ cursor: storyArgs.parentCursor }}> | ||
| <Action {...componentArgs} /> | ||
| {componentArgs.bottomBorder && <div style={{ padding: '16px', fontSize: '0.75em', color: '#888' }}> | ||
| Note: Adding this here because the bottom border seen above only renders when the action is not the last child of its parent. | ||
| </div>} | ||
| </div> | ||
| </Layout>; | ||
| } | ||
| }; | ||
| export default meta; | ||
|
|
||
| export const WithClickEvent: Story = { | ||
| args: {...baseArgs}, | ||
| render: render | ||
| } | ||
|
|
||
| export const WithClass: Story = { | ||
| args: {...baseArgs, className: "action-story-primary", renderAs: "div"}, | ||
| render: render | ||
| } | ||
|
|
||
| export const WithIcon: Story = { | ||
| args: {...baseArgs, icon: <FontAwesomeSvgIcon icon={faFile} color="#2e6e9e" />}, | ||
| render: render | ||
| } | ||
|
|
||
| export const WithTitleIcon: Story = { | ||
| args: {...baseArgs, titleIcon: <FontAwesomeSvgIcon icon={faFile} color="#2e6e9e" />}, | ||
| render: render | ||
| } | ||
| export const Default: StoryObj<ActionStoryArgs> = { | ||
| args: { | ||
| colorScheme: 'auto', | ||
| title: 'Baseline Survey', | ||
| subtitle: 'Tap here to start your baseline survey', | ||
| withClass: false, | ||
| withIcon: false, | ||
| withTitleIcon: false, | ||
| withIndicator: false, | ||
| withIndicatorIcon: false, | ||
| withIndicatorValue: false, | ||
| indicatorPosition: 'default', | ||
| bottomBorder: false, | ||
| withClickHandler: false, | ||
| titleColor: '', | ||
| subtitleColor: '', | ||
| parentCursor: 'not set', | ||
| renderAs: 'default' as any | ||
| }, | ||
| argTypes: { | ||
| colorScheme: { | ||
| name: 'color scheme', | ||
| control: 'radio', | ||
| options: ['auto', 'light', 'dark'] | ||
| }, | ||
| title: { | ||
| name: 'title', | ||
| control: 'text' | ||
| }, | ||
| subtitle: { | ||
| name: 'subtitle', | ||
| control: 'text' | ||
| }, | ||
| withClass: { | ||
| name: 'with class', | ||
| control: 'boolean' | ||
| }, | ||
| withIcon: { | ||
| name: 'with icon', | ||
| control: 'boolean' | ||
| }, | ||
| withTitleIcon: { | ||
| name: 'with title icon', | ||
| control: 'boolean' | ||
| }, | ||
| withIndicator: { | ||
| name: 'with indicator', | ||
| control: 'boolean' | ||
| }, | ||
| withIndicatorIcon: { | ||
| name: 'with indicator icon', | ||
| control: 'boolean' | ||
| }, | ||
| withIndicatorValue: { | ||
| name: 'with indicator value', | ||
| control: 'boolean' | ||
| }, | ||
| indicatorPosition: { | ||
| name: 'indicator position', | ||
| control: 'radio', | ||
| options: ['default', 'topRight'] | ||
| }, | ||
| bottomBorder: { | ||
| name: 'with bottom border', | ||
| control: 'boolean' | ||
| }, | ||
| withClickHandler: { | ||
| name: 'with click handler', | ||
| control: 'boolean' | ||
| }, | ||
| titleColor: { | ||
| name: 'title color', | ||
| control: 'color' | ||
| }, | ||
| subtitleColor: { | ||
| name: 'subtitle color', | ||
| control: 'color' | ||
| }, | ||
| parentCursor: { | ||
| name: 'parent cursor', | ||
| control: 'radio', | ||
| options: ['not set', 'pointer', 'crosshair'], | ||
| mapping: { | ||
| ['not set']: undefined | ||
| } | ||
| }, | ||
| renderAs: { | ||
| name: 'render as', | ||
| control: 'radio', | ||
| options: ['default', 'button', 'div'], | ||
| mapping: { | ||
| default: undefined | ||
| } | ||
| }, | ||
| ...argTypesToHide([ | ||
| 'titleIcon', 'icon', 'onClick', 'className', | ||
| 'indicator', 'indicatorIcon', 'indicatorValue', | ||
| 'innerRef' | ||
| ]) | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import Action from "../Action/Action"; | |
| import Layout from "../Layout" | ||
| import Card, { CardProps } from "./Card" | ||
| import "./Card.stories.css"; | ||
| import { Goal } from '../../container'; | ||
|
|
||
| export default { | ||
| title: "Presentational/Card", | ||
|
|
@@ -43,4 +44,18 @@ export const HighlightVariant = { | |
| children: <Action onClick={() => {}} title="Baseline Survey" subtitle="Tap here to start your baseline survey" /> | ||
| }, | ||
| render: render | ||
| }; | ||
|
|
||
| export const ClickableCard = { | ||
| args: { | ||
| children: <> | ||
| <Action title="See more details" bottomBorder /> | ||
| <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}> | ||
| <Goal variant="compact" label="Goal 1" targetValue={5} maxValue={10} valueProvider={{ type: 'static integer', getValue: async () => 7 }} /> | ||
| <Goal variant="compact" label="Goal 2" targetValue={5} maxValue={10} valueProvider={{ type: 'static integer', getValue: async () => 3 }} /> | ||
| </div> | ||
| </>, | ||
| onClick: () => console.log("Card Clicked!") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "See more details" made me expect to see more details, not a console statement. I think it would be better if the click event actually did something visible (even if it was as simple as changing a color or something) with a prompt to match. |
||
| }, | ||
| render: render | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ export interface CardProps { | |
| innerRef?: React.Ref<HTMLDivElement>; | ||
| variant?: "default" | "subtle" | "highlight"; | ||
| backgroundColor?: ColorDefinition; | ||
| onClick?: () => void; | ||
| style?: React.CSSProperties; | ||
| } | ||
|
|
||
|
|
@@ -36,7 +37,7 @@ export default function (props: CardProps) { | |
| let backgroundColor = resolveColor(layoutContext?.colorScheme, props.backgroundColor); | ||
|
|
||
| return ( | ||
| <div style={{...props.style, backgroundColor:backgroundColor}} ref={props.innerRef} className={classes.join(" ")}> | ||
| <div style={{ ...props.style, backgroundColor: backgroundColor, ...(props.onClick && { cursor: "pointer" }) }} ref={props.innerRef} className={classes.join(" ")} onClick={props.onClick}> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Chrome and Safari on Mac, I don't see any visible difference between the pointer on a clickable card vs a non-clickable card. |
||
| {props.children} | ||
| {props.children && variant === "highlight" && <ShinyOverlay />} | ||
| </div> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing something, but the story args here seem a little inconsistent compared to other stories. I'm used to seeing the actual component properties reflected in the story arguments. For example, on
BasicPointsForBadgesyou can control theBasicPointsForBadgesPropslike pointsPerBadge and progressBarColor. Here the story args seem to be activating specific scenarios, but I thought that was more normally done with separate stories?