diff --git a/packages/orbit-components/src/Card/Card.stories.tsx b/packages/orbit-components/src/Card/Card.stories.tsx index afc4c5205b..26fee3d8e8 100644 --- a/packages/orbit-components/src/Card/Card.stories.tsx +++ b/packages/orbit-components/src/Card/Card.stories.tsx @@ -18,6 +18,8 @@ type CardPropsAndCustomArgs = React.ComponentProps & { sectionTitle: string; sectionDescription: string; initialExpanded?: boolean; + onClick: () => void; + buttonClick: () => void; }; const meta: Meta = { @@ -96,7 +98,7 @@ export const CardWithActions: Story = { + Button } @@ -263,7 +265,7 @@ export const CardWithDefaultExpanded: Story = { initialExpanded={initialExpanded} onExpand={action("onExpand")} actions={ - + Close } @@ -294,11 +296,11 @@ export const CardWithDefaultExpanded: Story = { }; export const CardWithMixedSections: Story = { - render: ({ sectionTitle, sectionDescription, ...args }) => ( + render: ({ sectionTitle, sectionDescription, onClick, buttonClick, ...args }) => ( + Button } @@ -307,7 +309,7 @@ export const CardWithMixedSections: Story = { expandable title={sectionTitle} actions={ - + Button } @@ -321,16 +323,53 @@ export const CardWithMixedSections: Story = { Section Content - Button} /> + Button} + /> + + Section Content with onClick + + + Button + + } + title={sectionTitle} + description={sectionDescription} + > + Expandable section Content with onClick and actions + + + Button + + } + title={sectionTitle} + description={sectionDescription} + > + Non-expandable section Content with onClick and actions + ), + args: { + onClick: action("onClick"), + buttonClick: action("buttonClick"), + }, + parameters: { controls: { - exclude: ["labelClose", "initialExpanded", "expanded"], + exclude: ["labelClose", "initialExpanded", "expanded", "onClick", "buttonClick"], }, }, }; + export const LoadingCard: Story = { render: args => ( diff --git a/packages/orbit-components/src/Card/CardSection/index.tsx b/packages/orbit-components/src/Card/CardSection/index.tsx index 5551bc7631..8d798753a4 100644 --- a/packages/orbit-components/src/Card/CardSection/index.tsx +++ b/packages/orbit-components/src/Card/CardSection/index.tsx @@ -8,8 +8,37 @@ import { ELEMENT_OPTIONS } from "../../Heading/consts"; import type { Props } from "./types"; import Header from "../components/Header"; import Expandable from "./components/Expandable"; +import Stack from "../../Stack"; import handleKeyDown from "../../utils/handleKeyDown"; +const ContentWrapper = ({ + onClick, + className, + children, +}: Pick & { className?: string }) => ( + // eslint-disable-next-line jsx-a11y/no-static-element-interactions +
+ {children} +
+); + +const Actions = ({ actions }) => ( + + {actions} + +); + export default function CardSection({ title, titleAs = ELEMENT_OPTIONS.DIV, @@ -36,6 +65,8 @@ export default function CardSection({ }, [isControlled, expanded]); function handleClick() { + onClick?.(); + if (!isControlled) { setOpened(state => !state); } @@ -51,77 +82,90 @@ export default function CardSection({ return ( // Needs to capture bubbled click events from the + + {actions && } + )} - {(title != null || header != null) && !expandable && ( -
-
+
+ +
+ + {actions && }
)} {children && expandable && ( -
-
+
+ {children} -
+
)} {children && !expandable && ( -
{children} -
+ )}
); diff --git a/packages/orbit-components/src/Card/README.md b/packages/orbit-components/src/Card/README.md index 804d4eff57..4cd3ea2e6a 100644 --- a/packages/orbit-components/src/Card/README.md +++ b/packages/orbit-components/src/Card/README.md @@ -61,7 +61,6 @@ import Card, { CardSection } from "@kiwicom/orbit-components/lib/Card"; | initialExpanded | `boolean` | `false` | Initial state of expandable CardSection when it mounts in uncontrolled variant. Can only be used if `expandable` is `true`. | | noSeparator | `Boolean` | | Optional prop to turn off Separator between `header` and `children` | | onClick | `event => void \| Promise` | | Function for handling the onClick event. | -| | | onClose | `() => void \| Promise` | | Callback that is triggered when section is closing | | onExpand | `() => void \| Promise` | | Callback that is triggered when section is expanding | | title | `React.Node` | | The title of the CardSection |