Skip to content

Commit

Permalink
Release from next to main (#120)
Browse files Browse the repository at this point in the history
* feat(packages): add inline Alert component (#106)

Add inline alert component to feedback indicators based on Figma sketches:
https://www.figma.com/file/gpHv46zswMNeepUDyQfpS8/Feedback-indicators?node-id=274%3A31588

### Features

* **packages:** add inline Alert component ([#106](#106)) ([ddfe084](ddfe084))

* docs: don't disable button on modal

* feat(alert): add expand and collapse behaviour to inline alert (#114)

* refactor(expandable): extract transition animation from Expandable

Create AnimatedExpansion component that handles expand-collapse animation in Expandable, making it
possible to easily add this behaviour to other components.

* feat(alert): add expansion and collapsion behaviour to inline alert

Wrap Alert in AnimatedExpansion component to make it appear and disappear smoothly

* feat(alert): remove neutral variant of inline alert

* **alert:** add expand and collapse behaviour to inline alert ([#114](#114)) ([075f314](075f314))

* fix(affix): Add aria-label to Affix icons

Screen readers will use the aria-label on the SVG only if the button wrapper has no label. So in that sense, these default labels are like fallbacks.

* chore(release): 1.2.0-next.3 [skip ci]

# [1.2.0-next.3](v1.2.0-next.2...v1.2.0-next.3) (2022-06-07)

### Bug Fixes

* **affix:** Add aria-label to Affix icons ([17fab00](17fab00))

* fix: bump component-classes to get Step fix

* chore(deps): change to css/component-classes

* fix(animated-expansion): rename to ExpandTransition and check if element ref exists (#119)

Fixes an error 'Argument of type 'null' is not assignable to parameter of type 'HTMLElement'.

* chore(release): 1.2.0-next.4 [skip ci]

# [1.2.0-next.4](v1.2.0-next.3...v1.2.0-next.4) (2022-06-08)

### Bug Fixes

* **animated-expansion:** rename to ExpandTransition and check if element ref exists ([#119](#119)) ([b7a8026](b7a8026))
* bump component-classes to get Step fix ([5d99506](5d99506))

* chore(release): 1.2.0-next.5 [skip ci]

# [1.2.0-next.5](v1.2.0-next.4...v1.2.0-next.5) (2022-06-08)

### Bug Fixes

* bump component-classes to get Step fix ([c17ce7e](c17ce7e))

Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
Co-authored-by: Richard Walker <digitalsadhu@gmail.com>
Co-authored-by: Martin Storsletten <martin.storsletten@finn.no>
Co-authored-by: Benjamin Akar <benjaminakar2001@gmail.com>
Co-authored-by: Dave Honneffer <pearofducks@gmail.com>
  • Loading branch information
6 people authored Jun 8, 2022
1 parent c17ce7e commit 289290f
Show file tree
Hide file tree
Showing 23 changed files with 468 additions and 38 deletions.
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
# [1.2.0-next.5](https://github.com/fabric-ds/react/compare/v1.2.0-next.4...v1.2.0-next.5) (2022-06-08)


### Bug Fixes

* bump component-classes to get Step fix ([c17ce7e](https://github.com/fabric-ds/react/commit/c17ce7e83e1e78aca28e867dbf29331d69c549fe))

# [1.2.0-next.4](https://github.com/fabric-ds/react/compare/v1.2.0-next.3...v1.2.0-next.4) (2022-06-08)


### Bug Fixes

* **animated-expansion:** rename to ExpandTransition and check if element ref exists ([#119](https://github.com/fabric-ds/react/issues/119)) ([b7a8026](https://github.com/fabric-ds/react/commit/b7a8026dd17e6c53c1fe3b1831964b104bfc5087))
* bump component-classes to get Step fix ([5d99506](https://github.com/fabric-ds/react/commit/5d99506bcf45f531522670e6a910f11e671c1a54))

# [1.2.0-next.3](https://github.com/fabric-ds/react/compare/v1.2.0-next.2...v1.2.0-next.3) (2022-06-07)


### Bug Fixes

* **affix:** Add aria-label to Affix icons ([17fab00](https://github.com/fabric-ds/react/commit/17fab00e1f939531a613df6e2ba9e752e5e9d23e))

# [1.2.0-next.2](https://github.com/fabric-ds/react/compare/v1.2.0-next.1...v1.2.0-next.2) (2022-06-02)


### Features

* **alert:** add expand and collapse behaviour to inline alert ([#114](https://github.com/fabric-ds/react/issues/114)) ([075f314](https://github.com/fabric-ds/react/commit/075f314adfa468960a42f7c87af855d2f1ddce6d))

# [1.2.0-next.1](https://github.com/fabric-ds/react/compare/v1.1.1...v1.2.0-next.1) (2022-05-31)


### Features

* **packages:** add inline Alert component ([#106](https://github.com/fabric-ds/react/issues/106)) ([ddfe084](https://github.com/fabric-ds/react/commit/ddfe0842c2af00e3dc531fbff25d18f395a5dfe7))

## [1.1.1](https://github.com/fabric-ds/react/compare/v1.1.0...v1.1.1) (2022-05-23)


Expand Down
5 changes: 5 additions & 0 deletions docs/src/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Route,
Switch as ReactSwitch,
} from 'react-router-dom';
import Alert from '../../packages/alert/docs/Alert.mdx';
import Box from '../../packages/box/docs/Box.mdx';
import Breadcrumbs from '../../packages/breadcrumbs/docs/Breadcrumbs.mdx';
import Button from '../../packages/button/docs/Button.mdx';
Expand Down Expand Up @@ -46,6 +47,10 @@ const App = () => {
<Home />
</Route>

<Route path="/alert">
<Alert />
</Route>

<Route path="/modal">
<Modal />
</Route>
Expand Down
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
{
"title": "Feedback indicators",
"open": true,
"items": [{ "title": "Steps", "href": "/steps" }]
"items": [
{ "title": "Alert", "href": "/alert" },
{ "title": "Steps", "href": "/steps" }
]
},
{
"title": "Forms",
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabric-ds/react",
"version": "1.1.1",
"version": "1.2.0-next.5",
"repository": "git@github.com:fabric-ds/react.git",
"license": "ISC",
"type": "module",
Expand Down Expand Up @@ -48,9 +48,7 @@
"@babel/core": "^7.12.10",
"@chbphone55/classnames": "^2.0.0",
"@eik/esbuild-plugin": "^1.1.0",
"@fabric-ds/component-classes": "^0.0.38",
"@fabric-ds/icons": "^0.3.12",
"@fabric-ds/tailwind-config": "^0.5.20",
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/react": "1.6.22",
"@semantic-release/changelog": "^6.0.1",
Expand Down Expand Up @@ -105,7 +103,7 @@
"dependencies": {
"@chbphone55/classnames": "^2.0.0",
"@fabric-ds/core": "0.0.13",
"@fabric-ds/css": "^1.1.2",
"@fabric-ds/css": "^1.1.4",
"d3-scale": "^4.0.2",
"react-focus-lock": "^2.5.2",
"react-spring": "^8.0.27",
Expand Down
6 changes: 5 additions & 1 deletion packages/_helpers/affix.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { suffix, prefix } from '@fabric-ds/component-classes';
import { suffix, prefix } from '@fabric-ds/css/component-classes';
import { classNames } from '@chbphone55/classnames';

interface AffixProps {
Expand Down Expand Up @@ -43,6 +43,8 @@ export function Affix(props: AffixProps) {
<>
{props.clear && (
<svg
role="img"
aria-label="X"
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
Expand All @@ -60,6 +62,8 @@ export function Affix(props: AffixProps) {

{props.search && (
<svg
role="img"
aria-label="Forstørrelsesglass"
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
Expand Down
53 changes: 53 additions & 0 deletions packages/_helpers/expand-transition.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { PropsWithChildren, useEffect, useRef, useState } from 'react';
import { collapse, expand } from 'element-collapse';
import { classNames } from '@chbphone55/classnames';

export function ExpandTransition({
show,
children,
}: PropsWithChildren<{ show?: Boolean }>) {
const [isExpanded, setIsExpanded] = useState(show);
const expandableRef = useRef<HTMLDivElement>(null);
const isMounted = useRef(false);

async function collapseElement(el: HTMLElement) {
await new Promise((resolve) => {
collapse(el, resolve);
});
setIsExpanded(false);
}

function expandElement(el: HTMLElement) {
expand(el);
setIsExpanded(true);
}

useEffect(() => {
// Don't do anything at first render
if (!isMounted.current) {
isMounted.current = true;
return;
}

if (!expandableRef.current) return;

if (show) {
expandElement(expandableRef.current);
} else {
collapseElement(expandableRef.current);
}
}, [show]);

return (
<div
ref={expandableRef}
className={classNames({
'overflow-hidden': true,
'h-0 invisible': !isExpanded,
})}
aria-hidden={!isExpanded}
>
{children}
</div>
);
}
1 change: 1 addition & 0 deletions packages/_helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { Clickable } from './clickable';
export { DeadToggle } from './dead-toggle';
export { Affix } from './affix';
export { ExpandTransition } from './expand-transition';
80 changes: 80 additions & 0 deletions packages/alert/docs/Alert.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { Alert } from '../src';
import { Button } from '../../button/src';

# Alert

Alert is an inline component used for displaying different types of messages.

## Import

```js
import { Alert } from '@fabric-ds/react';
```

## Visual Options

### Expandable behaviour

```jsx example
function ExpandableAlert() {
const [show, setShow] = React.useState(true);

return (
<>
<Alert type="info" show={show}>
<p className="font-bold">Title Caption-Strong</p>
<p>This is the message text that can be short or a little bit long</p>
<a>Link to more information</a>
<div className="mt-8 space-x-8">
<Button small>Primary CTA</Button>
<Button small secondary quiet>
Secondary
</Button>
</div>
</Alert>

<Button className="mt-16" small primary onClick={() => setShow(!show)}>
{show ? 'Hide alert' : 'Show alert'}
</Button>
</>
);
}
```

### Negative

```jsx example
<Alert type="negative" show>
This is the message text that can be short or a little bit long
</Alert>
```

### Positive

```jsx example
<Alert type="positive" show>
This is the message text that can be short or a little bit long
</Alert>
```

### Warning

```jsx example
<Alert type="warning" show>
This is the message text that can be short or a little bit long
</Alert>
```

### Info

```jsx example
<Alert type="info" show>
This is the message text that can be short or a little bit long
</Alert>
```

## Props

```props packages/alert/src/component.tsx

```
123 changes: 123 additions & 0 deletions packages/alert/src/component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { classNames } from '@chbphone55/classnames';
import React, { PropsWithChildren, ReactElement } from 'react';
import { AlertProps } from '.';
import { ExpandTransition } from '../../_helpers';

export function Alert({
show,
type,
children,
...props
}: PropsWithChildren<AlertProps>) {
const { color, icon } = styleMap[type];

return (
<ExpandTransition show={show}>
<div
className={classNames(
props.className,
`flex p-16 border rounded-4 border-l-4 bg-${color}-50 border-${color}-300`,
)}
style={{ borderLeftColor: `var(--f-${color}-600)`, ...props.style }}
>
<div className={`mr-8 text-${color}-600`}>{icon}</div>
<div className="last-child:mb-0 text-14">{children}</div>
</div>
</ExpandTransition>
);
}

const styleMap: {
[key in AlertProps['type']]: { color: String; icon: ReactElement };
} = {
negative: {
color: 'red',
icon: (
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="none"
>
<path
d="M4.1.586A2 2 0 0 1 5.516 0h4.97A2 2 0 0 1 11.9.586L15.413 4.1A2 2 0 0 1 16 5.514v4.97a2 2 0 0 1-.586 1.415L11.9 15.413a2 2 0 0 1-1.415.586h-4.97a2 2 0 0 1-1.414-.586L.586 11.9A2 2 0 0 1 0 10.485v-4.97A2 2 0 0 1 .586 4.1L4.1.586Z"
fill="currentColor"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M8 3.25a.75.75 0 0 1 .75.75v5a.75.75 0 0 1-1.5 0V4A.75.75 0 0 1 8 3.25Z"
fill="#fff"
/>
<path d="M8.8 11.8a.8.8 0 1 1-1.6 0 .8.8 0 0 1 1.6 0Z" fill="#fff" />
</svg>
),
},
positive: {
color: 'green',
icon: (
<svg
width="16"
height="16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<circle
cx="8"
cy="8"
r="8"
transform="rotate(180 8 8)"
fill="currentColor"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M11.5 4.94c.3.27.34.75.06 1.06l-4 4.5a.75.75 0 0 1-1.09.03l-2-2a.75.75 0 0 1 1.06-1.06l1.44 1.44L10.44 5a.75.75 0 0 1 1.06-.07Z"
fill="#fff"
/>
</svg>
),
},
warning: {
color: 'yellow',
icon: (
<svg
width="16"
height="16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M.24 12 6.16 1.09a2.1 2.1 0 0 1 3.68 0l5.92 10.93c.73 1.36-.28 2.99-1.85 2.99H2.1a2.04 2.04 0 0 1-1.85-3Z"
fill="currentColor"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M8 3.25c.41 0 .75.34.75.75v5a.75.75 0 0 1-1.5 0V4c0-.41.34-.75.75-.75Z"
fill="#fff"
/>
<path d="M8.8 11.8a.8.8 0 1 1-1.6 0 .8.8 0 0 1 1.6 0Z" fill="#fff" />
</svg>
),
},
info: {
color: 'aqua',
icon: (
<svg
width="16"
height="16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<circle cx="8" cy="8" r="8" fill="currentColor" />
<path
fillRule="evenodd"
clipRule="evenodd"
d="M7.25 12a.75.75 0 0 0 1.5 0V8a.75.75 0 0 0-1.5 0v4ZM8 4a1 1 0 1 0 0 2 1 1 0 0 0 0-2Z"
fill="#fff"
/>
</svg>
),
},
};
2 changes: 2 additions & 0 deletions packages/alert/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Alert } from './component';
export type { AlertProps } from './props';
Loading

0 comments on commit 289290f

Please sign in to comment.