Skip to content

Commit

Permalink
Feature/toggletip (#745)
Browse files Browse the repository at this point in the history
Token changes:
- todo-toggletip-* tokens renamed to rhc-toggletip-*

---------

Co-authored-by: Ruben Smit <[email protected]>
  • Loading branch information
Rerbun and Ruben Smit authored Oct 11, 2024
1 parent 388c68b commit 33ac15f
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/components-css/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
@import "table/index";
@import "textarea/index";
@import "textbox/index";
@import "toggletip/index";
@import "unordered-list/index";
59 changes: 59 additions & 0 deletions packages/components-css/toggletip/_mixin.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Community for NL Design System
*/

@mixin rhc-toggletip {
background-color: transparent;
border-radius: var(--rhc-toggletip-border-radius);
display: inline-flex;
flex-direction: column;
size: var(--rhc-toggletip-size);
}

@mixin rhc-toggletip__summary {
cursor: pointer;
display: inline-flex;
margin-block-end: var(--rhc-toggletip-gap, 16px);
max-inline-size: var(--rhc-toggletip-size);
size: var(--rhc-toggletip-size);
}

@mixin rhc-toggletip__button {
background-color: var(--rhc-toggletip-background-color);
border-color: var(--rhc-toggletip-border-color);
border-radius: var(--rhc-toggletip-border-radius);
border-width: var(--rhc-toggletip-border-width);
color: var(--rhc-toggletip-color);
cursor: pointer;
display: inline-flex;
max-inline-size: var(--rhc-toggletip-size);
padding-block: 0;
padding-inline: 0;
size: var(--rhc-toggletip-size);
}

@mixin rhc-toggletip__button--no-pointer-events {
pointer-events: none;
}

@mixin rhc-toggletip__icon {
size: var(--rhc-toggletip-icon-size);
}

@mixin rhc-toggletip--active {
background-color: var(--rhc-toggletip-active-background-color);
border-color: var(--rhc-toggletip-active-border-color);
border-style: solid;
color: var(--rhc-toggletip-active-color);
}

@mixin rhc-toggletip--hover {
background-color: var(--rhc-toggletip-hover-background-color);
color: var(--rhc-toggletip-hover-color);
}

@mixin rhc-toggletip--focus {
background-color: var(--rhc-toggletip-focus-background-color);
color: var(--rhc-toggletip-focus-color);
}
48 changes: 48 additions & 0 deletions packages/components-css/toggletip/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @license EUPL-1.2
* Copyright (c) 2021 Community for NL Design System
*/

@import "./mixin";

.rhc-toggletip {
@include rhc-toggletip;
}

.rhc-toggletip__summary {
@include rhc-toggletip__summary;
}

.rhc-toggletip__button {
@include rhc-toggletip__button;
}

.rhc-toggletip__summary .rhc-toggletip__button {
// If button is not used standalone the summary should take precedence
@include rhc-toggletip__button--no-pointer-events;
}

.rhc-toggletip__button:focus {
@include rhc-toggletip--focus;
}

.rhc-toggletip__button:hover {
@include rhc-toggletip--hover;
}

.rhc-toggletip__summary:focus .rhc-toggletip__button {
@include rhc-toggletip--focus;
}

.rhc-toggletip__summary:hover .rhc-toggletip__button {
@include rhc-toggletip--hover;
}

.rhc-toggletip:active .rhc-toggletip__button,
.rhc-toggletip[open] .rhc-toggletip__button {
@include rhc-toggletip--active;
}

.rhc-toggletip__icon {
@include rhc-toggletip__icon;
}
46 changes: 46 additions & 0 deletions packages/components-react/src/Toggletip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import clsx from 'clsx';
import { DetailsHTMLAttributes, ForwardedRef, forwardRef, PropsWithChildren, ReactNode } from 'react';
import { Alert } from './Alert';
import { Icon } from './icon/Icon';

export interface ToggletipProps extends DetailsHTMLAttributes<HTMLDetailsElement> {
className?: string;
}

export const ToggletipButton = forwardRef(
({ children }: { children?: ReactNode }, ref: ForwardedRef<HTMLButtonElement>) => {
return (
<button className="rhc-toggletip__button" ref={ref}>
<Icon className="rhc-toggletip__icon" icon="info" />
{children}
</button>
);
},
);
ToggletipButton.displayName = 'ToggletipButton';

export const ToggletipContent = forwardRef(
({ children }: { children: ReactNode }, ref: ForwardedRef<HTMLDivElement>) => {
return (
<div className="rhc-toggletip__content" ref={ref}>
<Alert type="info">{children}</Alert>
</div>
);
},
);
ToggletipContent.displayName = 'ToggletipContent';

export const Toggletip = forwardRef(
({ children, className, ...restProps }: PropsWithChildren<ToggletipProps>, ref: ForwardedRef<HTMLDetailsElement>) => {
return (
<details className={clsx('rhc-toggletip', className)} ref={ref} {...restProps}>
<summary className="rhc-toggletip__summary">
<ToggletipButton />
</summary>
<ToggletipContent>{children}</ToggletipContent>
</details>
);
},
);

Toggletip.displayName = 'Toggletip';
5 changes: 3 additions & 2 deletions packages/components-react/src/icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
IconHeart,
IconHome,
IconInfoCircle,
IconInfoSmall,
IconInfoSquare,
IconLink,
IconLock,
Expand Down Expand Up @@ -80,7 +81,6 @@ export const IconenSet: Partial<Record<RijkshuisstijlIconID, ReactNode>> = {
activiteit: <IconCalendarCheck />,
'agile-werken': <IconArrowIteration />,
'alert-circle': <IconAlertCircle />,

'api-inrichting': <IconApi />,
'arrows-sort': <IconArrowsSort />,
audio: <IconVolume />,
Expand All @@ -107,8 +107,9 @@ export const IconenSet: Partial<Record<RijkshuisstijlIconID, ReactNode>> = {
'haakse-pijl': <IconCornerLeftUp />,
hashtag: <IconHash />,
home: <IconHome />,
info: <IconInfoSquare />,
info: <IconInfoSmall />,
'info-circle': <IconInfoCircle />,
'info-square': <IconInfoSquare />,
inloggen: <IconLogin2 />,
instellingen: <IconSettings />,
'interne-link': <IconLink />,
Expand Down
1 change: 1 addition & 0 deletions packages/components-react/src/icon/IconTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export type RijkshuisstijlIconID =
| 'home'
| 'info'
| 'info-circle'
| 'info-square'
| 'inloggen'
| 'instellingen'
| 'interne-link'
Expand Down
1 change: 1 addition & 0 deletions packages/components-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export { TableCaption } from './TableCaption';
export { TableCell, type TableCellProps } from './TableCell';
export { TableHeaderCell, type TableHeaderCellProps } from './TableHeaderCell';
export { Textbox, type TextboxProps } from './Textbox';
export { Toggletip, ToggletipButton, ToggletipContent, type ToggletipProps } from './Toggletip';
export {
UnorderedList,
UnorderedListItem,
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook/src/community/alert.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Alert } from '@rijkshuisstijl-community/components-react';
<Alert
heading="Heading"
headingLevel={3}
icon="info"
icon="info-circle"
textContent="Lorem ipsum dolor sit amet, consectetur ad * isicing elit, sed do eiusmod *"
type="info"
/>;
Expand Down
17 changes: 17 additions & 0 deletions packages/storybook/src/community/toggletip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Toggletip } from '@rijkshuisstijl-community/components-react';
import { Meta, StoryObj } from '@storybook/react';

const meta = {
title: 'Rijkshuisstijl/Toggletip',
id: 'rhc-toggletip',
component: Toggletip,
args: {
children: 'Lorem ipsum dolor sit amet, consecteur ad * isicing elit, sed do eiusmod *',
},
} satisfies Meta<typeof Toggletip>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {};
10 changes: 5 additions & 5 deletions proprietary/design-tokens/figma/figma.tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -5977,7 +5977,7 @@
}
},
"components/toggletip": {
"todo": {
"rhc": {
"toggletip": {
"color": {
"value": "{rhc.color.wit}",
Expand All @@ -5995,6 +5995,10 @@
"value": "{rhc.border-radius.md}",
"type": "borderRadius"
},
"border-width": {
"value": "{rhc.border-width.default}",
"type": "borderWidth"
},
"icon": {
"size": {
"value": "{rhc.size.icon.functional}",
Expand Down Expand Up @@ -6038,10 +6042,6 @@
"value": "{rhc.color.feedback.info.default}",
"type": "color"
}
},
"border-width": {
"value": "{rhc.border-width.default}",
"type": "borderWidth"
}
}
}
Expand Down

0 comments on commit 33ac15f

Please sign in to comment.