Add iconStyle + onClick option and story shot for icon component

This commit is contained in:
Florian Scholdei
2020-04-16 12:34:28 +02:00
parent b9acc7c9f6
commit 7a8b1c0c06
4 changed files with 132 additions and 13 deletions

View File

@@ -0,0 +1,62 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import React, { FC } from "react";
import { storiesOf } from "@storybook/react";
import styled from "styled-components";
import Icon from "./Icon";
const Wrapper = styled.div`
* {
margin: 0.5rem;
}
`;
const Container: FC = ({ children }) => <Wrapper>{children}</Wrapper>;
const helloWorld = () => {
alert("Hello world!");
};
storiesOf("Icon", module)
.addDecorator(storyFn => <Container>{storyFn()}</Container>)
.add("default", () => (
<>
<Icon title="Download" name="download" color="info" />
<Icon title="Pull Request" name="code-branch fa-rotate-180" color="warning" />
<Icon title="Star" iconStyle="far" name="star" color="inherit" />
<Icon
title="Hello world!"
name="hand-sparkles"
className="has-background-primary-25"
onClick={() => helloWorld()}
/>
</>
))
.add("minimal", () => (
<>
<Icon name="download" />
<Icon name="icons" />
<Icon name="cat" />
</>
));

View File

@@ -26,21 +26,30 @@ import classNames from "classnames";
type Props = {
title?: string;
iconStyle: string;
name: string;
color: string;
className?: string;
onClick?: () => void;
};
export default class Icon extends React.Component<Props> {
static defaultProps = {
iconStyle: "fas",
color: "grey-light"
};
render() {
const { title, name, color, className } = this.props;
const { title, iconStyle, name, color, className, onClick } = this.props;
if (title) {
return <i title={title} className={classNames("fas", "fa-fw", "fa-" + name, `has-text-${color}`, className)} />;
return (
<i
title={title}
className={classNames(iconStyle, "fa-fw", "fa-" + name, `has-text-${color}`, className)}
onClick={onClick}
/>
);
}
return <i className={classNames("fas", "fa-" + name, `has-text-${color}`, className)} />;
return <i className={classNames(iconStyle, "fa-" + name, `has-text-${color}`, className)} onClick={onClick} />;
}
}

View File

@@ -32706,6 +32706,46 @@ exports[`Storyshots Forms|Textarea OnSubmit 1`] = `
</div>
`;
exports[`Storyshots Icon default 1`] = `
<div
className="Iconstories__Wrapper-sc-1g657fe-0 hCEjkH"
>
<i
className="fas fa-fw fa-download has-text-info"
title="Download"
/>
<i
className="fas fa-fw fa-code-branch fa-rotate-180 has-text-warning"
title="Pull Request"
/>
<i
className="far fa-fw fa-star has-text-inherit"
title="Star"
/>
<i
className="fas fa-fw fa-hand-sparkles has-text-grey-light has-background-primary-25"
onClick={[Function]}
title="Hello world!"
/>
</div>
`;
exports[`Storyshots Icon minimal 1`] = `
<div
className="Iconstories__Wrapper-sc-1g657fe-0 hCEjkH"
>
<i
className="fas fa-download has-text-grey-light"
/>
<i
className="fas fa-icons has-text-grey-light"
/>
<i
className="fas fa-cat has-text-grey-light"
/>
</div>
`;
exports[`Storyshots Layout|Footer Default 1`] = `
<footer
className="footer"