Skip to content

Commit

Permalink
Component with svg icons (#119)
Browse files Browse the repository at this point in the history
This component has a list of SVG icons which we use in our design
  • Loading branch information
Horay authored Jul 17, 2020
1 parent fd2e81a commit 3a3f43a
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 23,547 deletions.
23,546 changes: 0 additions & 23,546 deletions package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nordcloud/gnui",
"version": "0.4.12",
"version": "0.4.13",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "git://github.com/nordcloud/gnui.git",
Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export * from "./multiselect";
export * from "./selectbutton";
export * from "./datepicker";
export * from "./message";
export * from "./svgicon";
47 changes: 47 additions & 0 deletions src/components/svgicon/SVGIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from "react";
import styled, { css } from "styled-components";
import theme from "../../theme";
import { getViewBox } from "../../utils/svgicons";
import { getPath } from "../../utils/svgicons";

export interface SVGIconProps {
name: string;
color?: "success" | "danger" | "warning" | "notification" | "white";
size?: "sm" | "md" | "lg" | "xl" | "xxl";
[x: string]: any;
}

const StyledSVGIcon = styled.svg<SVGIconProps>`
fill: ${theme.colors.primary};
width: ${theme.iconSize.md};
height: ${theme.iconSize.md};
${({ color }) =>
color &&
css`
fill: ${theme.colors[color]};
`}
${({ size }) =>
size &&
css`
width: ${theme.iconSize[size]};
height: ${theme.iconSize[size]};
`}
`;

export const SVGIcon: React.FC<SVGIconProps> = ({ name, ...props }) => {
const ViewBox = getViewBox(name);
const Path = getPath(name);

return (
<StyledSVGIcon
{...props}
viewBox={ViewBox}
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
>
{Path}
</StyledSVGIcon>
);
};
1 change: 1 addition & 0 deletions src/components/svgicon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./SVGIcon";
79 changes: 79 additions & 0 deletions src/stories/SVGIcon.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { useState } from "react";
import styled from "styled-components";
import { Meta, Story, Preview } from "@storybook/addon-docs/blocks";
import { SVGIcon } from "../components/svgicon";
import { Container, Flex } from "../components/container";

<Meta title="Components/SVGIcon" component={SVGIcon} />

# SVGIcon

## Props

- `name`: `string`**required**
- `size`: `string`**optional**: "sm" | "md" | "lg" | "xl" | "xxl"
- `color`: `string`**optional**: "success" | "danger" | "warning" | "notification" | "white"

### Icons Sizes

<Preview>
<Story name="size">
<Flex justifyContent="space-evenly">
<SVGIcon name="dashboard" size="sm" />
<SVGIcon name="dashboard" />
<SVGIcon name="dashboard" size="lg" />
<SVGIcon name="dashboard" size="xl" />
<SVGIcon name="dashboard" size="xxl" />
</Flex>
</Story>
</Preview>

### Icons colors

<Preview>
<Story name="colors">
<Flex justifyContent="space-evenly">
<SVGIcon name="dashboard" />
<SVGIcon name="dashboard" color="success"/>
<SVGIcon name="dashboard" color="danger"/>
<SVGIcon name="dashboard" color="warning"/>
<SVGIcon name="dashboard" color="notification"/>
</Flex>
</Story>
</Preview>

### Menu Icons

<Preview>
<Story name="menu">
<Flex justifyContent="space-evenly">
<SVGIcon name="dashboard" size="lg" />
<SVGIcon name="application" size="lg" />
<SVGIcon name="cloudAccounts" size="lg" />
<SVGIcon name="resource" size="lg" />
<SVGIcon name="organizationalStructure" size="lg" />
<SVGIcon name="contactPersons" size="lg" />
<SVGIcon name="users" size="lg" />
<SVGIcon name="mappingRules" size="lg" />
<SVGIcon name="costSplittingRules" size="lg" />
<SVGIcon name="actionLog" size="lg" />
<SVGIcon name="businessUnitType" size="lg" />
</Flex>
</Story>
</Preview>

### UI Icons

<Preview>
<Story name="ui">
<Flex justifyContent="space-evenly">
<SVGIcon name="danger" />
<SVGIcon name="success" />
<SVGIcon name="info" />
<SVGIcon name="help" />
<SVGIcon name="plus" />
<SVGIcon name="minus" />
</Flex>
</Story>
</Preview>

11 changes: 11 additions & 0 deletions src/theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type ZIndex = {
[zIndex: string]: number | any;
};

type IconSize = { [key: string]: string };

export interface ThemeInterface {
colors: Colors;
typography: Typography;
Expand All @@ -45,6 +47,7 @@ export interface ThemeInterface {
breakpoints: Breakpoints;
zindex: ZIndex;
[aliases: string]: any;
iconSize: IconSize;
}

const theme: ThemeInterface = {
Expand Down Expand Up @@ -144,6 +147,14 @@ const theme: ThemeInterface = {
xl: 1200,
},

iconSize: {
sm: "0.875rem",
md: "1.5rem",
lg: "2rem",
xl: "3rem",
xxl: "5rem",
},

opacity: 0.7,
};

Expand Down
181 changes: 181 additions & 0 deletions src/utils/svgicons.tsx

Large diffs are not rendered by default.

0 comments on commit 3a3f43a

Please sign in to comment.