-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1758 from bryceosterhaus/1757
Fixes #1757 - Create @clay/label
- Loading branch information
Showing
13 changed files
with
314 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# clay-label | ||
|
||
React implementation for label from clay-css | ||
|
||
## Setup | ||
|
||
1. Install `yarn` | ||
|
||
2. Install local dependencies: | ||
|
||
``` | ||
yarn | ||
``` | ||
|
||
3. Build the code: | ||
|
||
``` | ||
yarn start | ||
``` | ||
|
||
4. Open the demo at `localhost:8080` on your browser. | ||
|
||
## Contribute | ||
|
||
We'd love to get contributions from you! Please, check our [Contributing Guidelines](https://github.com/liferay/clay/blob/master/CONTRIBUTING.md) to see how you can help us improve. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* © 2019 Liferay, Inc. <https://liferay.com> | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import ClayLabel from '../src/ClayLabel'; | ||
import {ClayIconSpriteContext} from '@clayui/icon'; | ||
|
||
import 'clay-css/lib/css/atlas.css'; | ||
|
||
const App: React.FunctionComponent = () => { | ||
const [active, setActive] = React.useState(true); | ||
|
||
return ( | ||
<ClayIconSpriteContext.Provider value="node_modules/clay-css/lib/images/icons/icons.svg"> | ||
<div> | ||
<ClayLabel>{'Default Label'}</ClayLabel> | ||
<ClayLabel displayType="info">{'Info Label'}</ClayLabel> | ||
<ClayLabel displayType="warning">{'Warning Label'}</ClayLabel> | ||
<ClayLabel displayType="danger">{'Danger Label'}</ClayLabel> | ||
<ClayLabel displayType="success">{'Success Label'}</ClayLabel> | ||
|
||
{active && ( | ||
<ClayLabel | ||
closeButtonProps={{ | ||
children: 'x', | ||
onClick: () => setActive(false), | ||
}} | ||
displayType="success" | ||
> | ||
{'Closable'} | ||
</ClayLabel> | ||
)} | ||
|
||
<ClayLabel href="#/foo/bar">{'Label w/ link'}</ClayLabel> | ||
</div> | ||
</ClayIconSpriteContext.Provider> | ||
); | ||
}; | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<img | ||
style="display: none;" | ||
src="../node_modules/clay-css/lib/images/icons/icons.svg" | ||
/> | ||
|
||
<body style="margin: 48px;"> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "@clayui/label", | ||
"version": "3.0.0", | ||
"description": "ClayLabel component", | ||
"license": "BSD-3-Clause", | ||
"repository": "https://github.com/liferay/clay/tree/master/packages/clay-label", | ||
"engines": { | ||
"node": ">=0.12.0", | ||
"npm": ">=3.0.0" | ||
}, | ||
"main": "lib/ClayLabel.js", | ||
"esnext:main": "src/ClayLabel.js", | ||
"jsnext:main": "src/ClayLabel.js", | ||
"files": ["lib", "src"], | ||
"scripts": { | ||
"build": "babel src --root-mode upward --out-dir lib --extensions .ts,.tsx", | ||
"build:types": "tsc --project ./tsconfig.declarations.json", | ||
"prepublishOnly": "npm run build && npm run build:types", | ||
"start": "webpack-dev-server --mode development", | ||
"test": "jest --config ../../jest.config.js" | ||
}, | ||
"keywords": ["clay", "react"], | ||
"dependencies": { | ||
"@clayui/icon": "^3.0.0", | ||
"classnames": "^2.2.6" | ||
}, | ||
"devDependencies": { | ||
"clay-css": "^2.12.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.1", | ||
"react-dom": "^16.8.1" | ||
}, | ||
"browserslist": ["extends browserslist-config-clay"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* © 2019 Liferay, Inc. <https://liferay.com> | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import classNames from 'classnames'; | ||
import Icon from '@clayui/icon'; | ||
|
||
type DisplayType = 'secondary' | 'info' | 'warning' | 'danger' | 'success'; | ||
|
||
interface Props | ||
extends React.BaseHTMLAttributes<HTMLAnchorElement | HTMLSpanElement> { | ||
/** | ||
* HTML properties that are applied to the 'x' button. | ||
*/ | ||
closeButtonProps?: React.ButtonHTMLAttributes<HTMLButtonElement>; | ||
|
||
/** | ||
* Determines the style of the label. | ||
*/ | ||
displayType?: DisplayType; | ||
|
||
/** | ||
* Flag to indicate if the label should be of the `large` variant. | ||
*/ | ||
large?: boolean; | ||
|
||
/** | ||
* Path to the location of the spritemap resource used for Icon. | ||
*/ | ||
spritemap?: string; | ||
} | ||
|
||
const ClayLabel: React.FunctionComponent<Props> = ({ | ||
children, | ||
className, | ||
closeButtonProps, | ||
displayType = 'secondary', | ||
href, | ||
large = false, | ||
spritemap, | ||
...otherProps | ||
}) => { | ||
const TagName = href ? 'a' : 'span'; | ||
|
||
return ( | ||
<TagName | ||
{...otherProps} | ||
className={classNames('label', className, { | ||
'label-dismissible': closeButtonProps, | ||
'label-lg': large, | ||
[`label-${displayType}`]: displayType, | ||
})} | ||
href={href} | ||
> | ||
<span className="label-item label-item-expand">{children}</span> | ||
|
||
{closeButtonProps && ( | ||
<span className="label-item label-item-after"> | ||
<button | ||
{...closeButtonProps} | ||
className="close" | ||
type="button" | ||
> | ||
<Icon spritemap={spritemap} symbol="times" /> | ||
</button> | ||
</span> | ||
)} | ||
</TagName> | ||
); | ||
}; | ||
|
||
export default ClayLabel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* © 2019 Liferay, Inc. <https://liferay.com> | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import * as TestRenderer from 'react-test-renderer'; | ||
import ClayLabel from '../ClayLabel'; | ||
|
||
describe('ClayLabel', () => { | ||
it('renders', () => { | ||
const testRenderer = TestRenderer.create( | ||
<ClayLabel>{'Default Label'}</ClayLabel> | ||
); | ||
|
||
expect(testRenderer.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders with a different displayType ', () => { | ||
const testRenderer = TestRenderer.create( | ||
<ClayLabel displayType="success">{'Success Label'}</ClayLabel> | ||
); | ||
|
||
expect(testRenderer.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders as a link ', () => { | ||
const testRenderer = TestRenderer.create( | ||
<ClayLabel href="#/foo/bar">{'Label w/ link'}</ClayLabel> | ||
); | ||
|
||
expect(testRenderer.toJSON()).toMatchSnapshot(); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/clay-label/src/__tests__/__snapshots__/ClayLabel.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ClayLabel renders 1`] = ` | ||
<span | ||
className="label label-secondary" | ||
> | ||
<span | ||
className="label-item label-item-expand" | ||
> | ||
Default Label | ||
</span> | ||
</span> | ||
`; | ||
|
||
exports[`ClayLabel renders as a link 1`] = ` | ||
<a | ||
className="label label-secondary" | ||
href="#/foo/bar" | ||
> | ||
<span | ||
className="label-item label-item-expand" | ||
> | ||
Label w/ link | ||
</span> | ||
</a> | ||
`; | ||
|
||
exports[`ClayLabel renders with a different displayType 1`] = ` | ||
<span | ||
className="label label-success" | ||
> | ||
<span | ||
className="label-item label-item-expand" | ||
> | ||
Success Label | ||
</span> | ||
</span> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"declarationDir": "./lib" | ||
}, | ||
"extends": "../../tsconfig.declarations.json", | ||
"include": ["src"], | ||
"exclude": ["**/__tests__/**"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* © 2019 Liferay, Inc. <https://liferay.com> | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
const path = require('path'); | ||
const HWP = require('html-webpack-plugin'); | ||
|
||
module.exports = { | ||
entry: path.join(__dirname, 'demo/App.tsx'), | ||
module: { | ||
rules: [ | ||
{loader: 'awesome-typescript-loader', test: /\.tsx?$/}, | ||
{enforce: 'pre', loader: 'source-map-loader', test: /\.js$/}, | ||
{ | ||
test: /\.css$/, | ||
use: ['style-loader', 'css-loader'], | ||
}, | ||
], | ||
}, | ||
plugins: [new HWP({template: path.join(__dirname, './demo/index.html')})], | ||
resolve: { | ||
extensions: ['.ts', '.tsx', '.js', '.json'], | ||
}, | ||
}; |