Skip to content

Commit 5779f52

Browse files
authored
fix: collapsible card fixes, titleExtra on accordion (#48)
* fix: collapsible state, titleExtra on accordion * Remove support for node 10 * fix types * v0.4.3 * Danger button * v0.4.4
1 parent 547a90c commit 5779f52

File tree

13 files changed

+69
-13
lines changed

13 files changed

+69
-13
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ${{ matrix.os }}
88
strategy:
99
matrix:
10-
node: ['10.x', '12.x', '14.x']
10+
node: ['12.x', '14.x']
1111
os: [ubuntu-latest, windows-latest, macOS-latest]
1212

1313
steps:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.4.2",
2+
"version": "0.4.4",
33
"license": "MIT",
44
"main": "dist/index.js",
55
"typings": "dist/index.d.ts",
@@ -9,7 +9,7 @@
99
],
1010
"source": "src/index.tsx",
1111
"engines": {
12-
"node": ">=10"
12+
"node": ">=12"
1313
},
1414
"scripts": {
1515
"start": "tsdx watch",

src/accordion/Accordion.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export function Accordion({ children }: AccordionProps) {
3030

3131
export interface AccordionItemProps {
3232
title: string;
33+
/**
34+
* An extra interactive element to be displayed next to the header
35+
*/
36+
titleExtra?: ReactNode;
3337
/**
3438
* A unique id for this part of the UI. Necessary for ally
3539
*/
@@ -39,10 +43,26 @@ export interface AccordionItemProps {
3943
}
4044

4145
export function AccordionItem(props: AccordionItemProps) {
42-
const { title, id, defaultIsOpen = true, children } = props;
46+
const { title, titleExtra, id, defaultIsOpen = true, children } = props;
4347
const [isOpen, setIsOpen] = useState(defaultIsOpen);
4448
const contentId = `${id}-content`,
4549
headerId = `${id}-heading`;
50+
51+
// Display the titleExtra inline
52+
const titleEl = titleExtra ? (
53+
<div
54+
css={css`
55+
display: flex;
56+
flex-direction: row;
57+
`}
58+
>
59+
<Text textSize="large">{title}</Text>
60+
{titleExtra}
61+
</div>
62+
) : (
63+
<Text textSize="large">{title}</Text>
64+
);
65+
4666
return (
4767
<div
4868
className={classNames('ac-accordion-item', {
@@ -85,7 +105,7 @@ export function AccordionItem(props: AccordionItemProps) {
85105
aria-controls={contentId}
86106
aria-expanded={isOpen}
87107
>
88-
<Text textSize="large">{title}</Text>
108+
{titleEl}
89109
<Icon
90110
svg={<ArrowIosDownwardOutline />}
91111
className="ac-accordion-itemIndicator"

src/button/Button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { buttonCSS } from './styles';
1212

1313
export interface ButtonProps extends BaseButtonProps {
1414
children?: ReactNode | string;
15-
variant: 'primary' | 'default';
15+
variant: 'primary' | 'default' | 'danger';
1616
disabled?: boolean;
1717
className?: string;
1818
onClick?: (e: SyntheticEvent<HTMLButtonElement>) => void;

src/button/styles.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ export const buttonCSS = css`
4646
background-color: ${theme.components.button.defaultHoverBackgroundColor};
4747
}
4848
}
49+
&[data-variant='danger'] {
50+
background-color: ${theme.colors.statusDanger};
51+
border-color: ${theme.components.button.dangerBorderColor};
52+
&:hover:not([disabled]) {
53+
background-color: ${theme.components.button.dangerHoverBackgroundColor};
54+
}
55+
}
4956
&[data-childless='false'] > i,
5057
& > .ac-spinner {
5158
margin-right: ${theme.spacing.margin4}px;

src/card/Card.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { classNames } from '../utils';
88
import { useId } from '@react-aria/utils';
99

1010
const headerTitleWrapCSS = css`
11+
flex: 1 1 auto;
1112
display: flex;
1213
flex-direction: column;
1314
& > h3,
@@ -51,7 +52,7 @@ export function Card({
5152
extra,
5253
className,
5354
titleExtra,
54-
collapsible,
55+
collapsible = false,
5556
defaultOpen = true,
5657
id,
5758
}: CardProps) {
@@ -108,7 +109,7 @@ export function Card({
108109
'is-open': isOpen,
109110
})}
110111
>
111-
<header css={headerCSS({ bordered: true })} id={headerId}>
112+
<header css={headerCSS({ bordered: true, collapsible })} id={headerId}>
112113
{titleComponent}
113114
{extra}
114115
</header>

src/card/CollapsibleCardTitle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function CollapsibleCardTitle(props: CollapsibleCardTitleProps) {
5252
className="ac-card-collapsible__trigger"
5353
css={css`
5454
transition: transform ease var(--collapsible-card-animation-duration);
55-
transform: rotate(180deg);
55+
transform: rotate(-90deg);
5656
margin-right: ${theme.spacing.padding8}px;
5757
`}
5858
aria-hidden={true}

src/card/TabbedCard.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export function TabbedCard(props: TabbedCardProps) {
2828
{...restProps}
2929
>
3030
{hasTitle ? (
31-
<header css={headerCSS({ bordered: false, height: 60 })}>
31+
<header
32+
css={headerCSS({ bordered: false, height: 60, collapsible: false })}
33+
>
3234
<Text textSize="xlarge" elementType="h3" weight="heavy">
3335
{title}
3436
</Text>

src/card/styles.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ const headerBorderCSS = css`
1818

1919
export const headerCSS = ({
2020
bordered,
21+
collapsible,
2122
height = cardHeaderHeight,
2223
}: {
2324
bordered: boolean;
25+
collapsible: boolean;
2426
height?: number;
2527
}) => css`
2628
display: flex;
@@ -30,6 +32,12 @@ export const headerCSS = ({
3032
align-items: center;
3133
padding: 0 16px;
3234
height: ${height}px;
35+
transition: background-color 0.2s ease-in-out;
36+
&:hover {
37+
background-color: ${collapsible
38+
? theme.colors.hoverBgColor
39+
: 'transparent'};
40+
}
3341
${bordered ? headerBorderCSS : ''}
3442
`;
3543

@@ -43,7 +51,6 @@ export const collapsibleCardCSS = css`
4351
display: flex;
4452
flex-direction: row;
4553
flex: 1 1 auto;
46-
justify-content: space-between;
4754
align-items: center;
4855
appearance: none;
4956
background-color: inherit;

src/theme.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ const theme = {
9797
primaryHoverBackgroundColor: '#5BAECC',
9898
defaultBorderColor: borderColors.lightGrayBorder,
9999
defaultHoverBackgroundColor: '#64768A',
100+
dangerBorderColor: lighten(0.1, '#F85149'),
101+
dangerHoverBackgroundColor: lighten(0.1, '#F85149'),
100102
},
101103
},
102104
typography: {

0 commit comments

Comments
 (0)