Skip to content

Commit

Permalink
Fixes #1941 - Implement panel component with collapse ability
Browse files Browse the repository at this point in the history
  • Loading branch information
bryceosterhaus committed May 1, 2019
1 parent cbb9cae commit 1b9127a
Show file tree
Hide file tree
Showing 10 changed files with 607 additions and 19 deletions.
51 changes: 42 additions & 9 deletions migrate-the-clay-components-from-v2-to-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ To get to the behavior of having a ClayLink with image, use the composition with

### API Changes

- `data` deprecated
- `defaultEventHandler` deprecated
- `elementClasses` renamed to `className`
- `icon` deprecated
- `imageAlt` deprecated
- `imageSrc` deprecated
- `label` deprecated in favor of `children`
- `spritemap` deprecated
- `style` renamed to `displayType`
- `data` deprecated
- `defaultEventHandler` deprecated
- `elementClasses` renamed to `className`
- `icon` deprecated
- `imageAlt` deprecated
- `imageSrc` deprecated
- `label` deprecated in favor of `children`
- `spritemap` deprecated
- `style` renamed to `displayType`

### Compositions

Expand Down Expand Up @@ -249,3 +249,36 @@ For example:
- `status` removed in favor of `warn`
- `feedback` added to determine if `progress-group-feedback` is used, default value is false unless value is 100.
- `warn` added to indicate `progress-warning` class

## ClayCollapse -> ClayPanel

ClayCollapse has been renamed to ClayPanel due to collapse being just a part of the panel functionality. ClayPanel is now simpler as it now manages its own expanded state internally. ClayPanel also is now created via composition with `<ClayPanel.Body>`, `<ClayPanel.Footer>`, `<ClayPanel.Header>` and `<ClayPanel.Group>`.

For example:

```jsx
<ClayPanel>
<ClayPanel.Header>{'Header!'}</ClayPanel.Header>
<ClayPanel.Body>{'Body!'}</ClayPanel.Body>
<ClayPanel.Footer>{'Footer!'}</ClayPanel.Footer>
</ClayPanel>

// or
<ClayPanel.Group>
<ClayPanel>
<ClayPanel.Body>{'One!'}</ClayPanel.Body>
</ClayPanel>
<ClayPanel>
<ClayPanel.Body>{'Two!'}</ClayPanel.Body>
</ClayPanel>
</ClayPanel.Group>
```

### API Changes

- `closedClasses` removed and uses clay's classes of `collapse` and `show`
- `collapsed` renamed to `defaultExpanded` which will only take effect on first render.
- `content` removed in favor of `children` prop
- `headers` removed in favor of composing with `<ClayPanel.Header>`
- `openClasses` removed and uses clay's class of `collapse`
- `transitionClasses` removed and manages transitions internally.
15 changes: 12 additions & 3 deletions packages/clay-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,29 @@
"main": "lib/index.js",
"module": "src/index.tsx",
"jsnext:main": "src/index.tsx",
"files": ["lib", "src"],
"files": [
"lib",
"src"
],
"scripts": {
"build": "cross-env NODE_ENV=production babel src --root-mode upward --out-dir lib --extensions .ts,.tsx",
"build:types": "cross-env NODE_ENV=production tsc --project ./tsconfig.declarations.json",
"prepublishOnly": "npm run build && npm run build:types",
"test": "jest --config ../../jest.config.js"
},
"keywords": ["clay", "react"],
"keywords": [
"clay",
"react"
],
"dependencies": {
"@clayui/icon": "^3.0.0",
"classnames": "^2.2.6"
},
"peerDependencies": {
"react": "^16.8.1",
"react-dom": "^16.8.1"
},
"browserslist": ["extends browserslist-config-clay"]
"browserslist": [
"extends browserslist-config-clay"
]
}
24 changes: 24 additions & 0 deletions packages/clay-panel/src/Body.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* © 2019 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import * as React from 'react';
import classNames from 'classnames';

interface Props extends React.HTMLAttributes<HTMLDivElement> {}

const ClayPanelBody: React.FunctionComponent<Props> = ({
children,
className,
...otherProps
}) => {
return (
<div {...otherProps} className={classNames('panel-body', className)}>
{children}
</div>
);
};

export default ClayPanelBody;
24 changes: 24 additions & 0 deletions packages/clay-panel/src/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* © 2019 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import * as React from 'react';
import classNames from 'classnames';

interface Props extends React.HTMLAttributes<HTMLDivElement> {}

const ClayPanelFooter: React.FunctionComponent<Props> = ({
children,
className,
...otherProps
}) => {
return (
<div {...otherProps} className={classNames('panel-footer', className)}>
{children}
</div>
);
};

export default ClayPanelFooter;
62 changes: 62 additions & 0 deletions packages/clay-panel/src/Group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* © 2019 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import * as React from 'react';
import classNames from 'classnames';

interface Props extends React.HTMLAttributes<HTMLDivElement> {
/**
* Flag to signify that `panel-group-fluid-first` class should be added.
* This class generally should be used inside card or sheet
*/
fluidFirst?: boolean;

/**
* Flag to signify that `panel-group-fluid-last` class should be added.
* This class generally should be used inside card or sheet
*/
fluidLast?: boolean;

/**
* Flag to signify that `panel-group-fluid` class should be added.
* This class generally should be used inside card or sheet
*/
fluid?: boolean;

/**
* Flag to signify that `panel-group-flush` class should be added.
* This class generally should be used inside card, sheet, or a type of padded container.
*/
flush?: boolean;
}

const ClayPanelGroup: React.FunctionComponent<Props> = ({
children,
className,
fluid,
fluidFirst,
fluidLast,
flush,
...otherProps
}) => {
return (
<div
{...otherProps}
aria-orientation="vertical"
className={classNames('panel-group', className, {
'panel-group-fluid': fluid,
'panel-group-fluid-first': fluidFirst,
'panel-group-fluid-last': fluidLast,
'panel-group-flush': flush,
})}
role="tablist"
>
{children}
</div>
);
};

export default ClayPanelGroup;
24 changes: 24 additions & 0 deletions packages/clay-panel/src/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* © 2019 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import * as React from 'react';
import classNames from 'classnames';

interface Props extends React.HTMLAttributes<HTMLDivElement> {}

const ClayPanelHeader: React.FunctionComponent<Props> = ({
children,
className,
...otherProps
}) => {
return (
<div {...otherProps} className={classNames('panel-header', className)}>
{children}
</div>
);
};

export default ClayPanelHeader;
157 changes: 157 additions & 0 deletions packages/clay-panel/src/__tests__/__snapshots__/index.tsx.snap
Original file line number Diff line number Diff line change
@@ -1 +1,158 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ClayPanel renders 1`] = `
<div
className="panel"
>
<div
className="panel-header"
>
<span
className="panel-title"
>
Display Title
</span>
</div>
<div
className="panel-header"
>
Header!
</div>
<div
className="panel-body"
>
Body!
</div>
<div
className="panel-footer"
>
Footer!
</div>
</div>
`;

exports[`ClayPanel renders with different displayType 1`] = `
<div
className="panel panel-secondary"
>
<div
className="panel-header"
>
<span
className="panel-title"
>
Display Title
</span>
</div>
<div
className="panel-header"
>
Header!
</div>
<div
className="panel-body"
>
Body!
</div>
<div
className="panel-footer"
>
Footer!
</div>
</div>
`;

exports[`ClayPanel renders with multiple panels 1`] = `
<div
aria-orientation="vertical"
className="panel-group"
role="tablist"
>
<div
className="panel"
>
<div
className="panel-header"
>
<span
className="panel-title"
>
Display Title
</span>
</div>
<div
className="panel-body"
>
Body!
</div>
</div>
<div
className="panel"
>
<div
className="panel-header"
>
<span
className="panel-title"
>
Display Title
</span>
</div>
<div
className="panel-body"
>
Body!
</div>
</div>
<div
className="panel"
>
<button
aria-expanded={false}
className="btn btn-unstyled panel-header panel-header-link collapse-icon collapse-icon-middle collapsed"
onClick={[Function]}
role="tab"
>
<span
className="panel-title"
>
Display Title
</span>
<span
className="collapse-icon-closed"
>
<svg
className="lexicon-icon lexicon-icon-angle-right"
role="presentation"
>
<use
xlinkHref="/foo/bar#angle-right"
/>
</svg>
</span>
<span
className="collapse-icon-open"
>
<svg
className="lexicon-icon lexicon-icon-angle-down"
role="presentation"
>
<use
xlinkHref="/foo/bar#angle-down"
/>
</svg>
</span>
</button>
<div
className="panel-collapse collapse"
role="tabpanel"
>
<div
className="panel-body"
>
Body!
</div>
</div>
</div>
</div>
`;
Loading

0 comments on commit 1b9127a

Please sign in to comment.