Skip to content

style: minor fixes to components #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69,656 changes: 43,038 additions & 26,618 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@
"react-dropzone": "^14.2.3",
"react-number-format": "^4.6.4",
"react-select": "^4.3.1",
"react-spring": "^9.5.5",
"react-table": "^7.7.0",
"styled-components": "^5.3.0"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@mdx-js/react": "^2.1.5",
"@semantic-release/git": "^9.0.0",
"@storybook/addon-actions": "^6.4.17",
"@storybook/addon-docs": "^6.5.13",
"@storybook/addon-essentials": "^6.4.17",
"@storybook/addon-links": "^6.4.17",
"@storybook/builder-webpack5": "^6.4.17",
Expand Down
17 changes: 17 additions & 0 deletions src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,20 @@ WithIcon.args = {
children: 'With icon',
icon: polyIcons.DeleteOutline,
};

export const WithColoredIcon = Template.bind({});
WithColoredIcon.args = {
variant: 'primary',
children: 'With icon',
fillIcon: false,
icon: polyIcons.GoogleColor,
};

export const WithCustomWidth = Template.bind({});
WithCustomWidth.args = {
variant: 'primary',
children: 'With icon',
fillIcon: false,
icon: polyIcons.GoogleColor,
width: '300px'
};
26 changes: 17 additions & 9 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export type ButtonProps = PropsWithChildren<{
size?: 's' | 'm' | 'l';
disabled?: boolean;
icon?: ComponentType;
fillIcon?: boolean,
iconPosition?: 'left' | 'right';
onClick?: () => void;
width?: string;
}>;

const sizeMap: Record<string, Record<string, string>> = {
Expand All @@ -41,11 +43,12 @@ const sizeMap: Record<string, Record<string, string>> = {
};

const Component = styled.button<ButtonProps>(
({ theme, variant, margin, size }) => {
({ theme, variant, margin, size, width }) => {
return {
...(theme.BUTTON[variant] || {}),
...(size ? sizeMap[size] : {}),
margin: getMargin({ theme, margin }),
...(width && {width: width})
};
},
);
Expand All @@ -58,28 +61,32 @@ const IconContainer = styled.span<any>(({ iconPosition }) => ({
fontSize: '19px',
}));

const StyledIcon = styled(Icon)<any>(({ theme, themeVariant }) => {
const StyledIcon = styled(Icon)<any>(({ theme, themeVariant, fillIcon }) => {
return {
color: theme.BUTTON[themeVariant].color,
svg: {
path: {
fill: theme.BUTTON[themeVariant].color,
},
},
...(fillIcon && {
svg: {
path: {
fill: theme.BUTTON[themeVariant].color,
},
}
}),
};
});

const renderIconContainer = (
icon: ComponentType,
variant: ButtonVariant,
iconPosition: string = IconPosition.Left,
fillIcon: boolean
) => (
<IconContainer iconPosition={iconPosition}>
<StyledIcon
themeVariant={variant}
icon={icon}
variant="basic"
size="14px"
fillIcon={fillIcon}
/>
</IconContainer>
);
Expand All @@ -90,6 +97,7 @@ export function Button(buttonProps: ButtonProps) {
size = 'm',
icon,
iconPosition,
fillIcon = true,
children,
variant,
...props
Expand All @@ -99,11 +107,11 @@ export function Button(buttonProps: ButtonProps) {
<Component size={size} type={type} variant={variant} {...props}>
{icon &&
(!iconPosition || iconPosition === IconPosition.Left) &&
renderIconContainer(icon, variant, iconPosition)}
renderIconContainer(icon, variant, iconPosition, fillIcon)}
{children}
{icon &&
iconPosition === IconPosition.Right &&
renderIconContainer(icon, variant, iconPosition)}
renderIconContainer(icon, variant, iconPosition, fillIcon)}
</Component>
);
}
17 changes: 10 additions & 7 deletions src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ export type IconProps = {
margin?: string;
color?: string;
bg?: string;
fillIcon?: boolean;
scale?: number;
rotate?: string;
};

const Component = styled.span<Omit<IconProps, 'icon'>>(
({ variant, margin, size, bg, scale, rotate, color, theme }) => ({
({ variant, margin, size, bg, scale, rotate, color, fillIcon, theme }) => ({
...(theme.ICON[variant] || {}),
display: 'inline-block',
margin: getMargin({ theme, margin }),
Expand All @@ -37,12 +38,14 @@ const Component = styled.span<Omit<IconProps, 'icon'>>(
...(scale ? { padding: `${(1 - scale) * 100}%` } : {}),
...(rotate ? { transform: `rotateZ(${rotate})` } : {}),
},
'svg > *': {
...theme.ICON[variant]['svg > *'],
...(color || theme.ICON[variant].fill
? { fill: color ? theme.COLOR[color] : theme.ICON[variant].fill }
: {}),
},
...(fillIcon && {
'svg > *': {
...theme.ICON[variant]['svg > *'],
...(color || theme.ICON[variant].fill
? { fill: color ? theme.COLOR[color] : theme.ICON[variant].fill }
: {}),
}
})
}),
);

Expand Down
9 changes: 9 additions & 0 deletions src/components/Input/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,12 @@ ReadOnly.args = {
placeholder: "Can't type here",
readOnly: true,
};

export const CustomWidth = Template.bind({});
CustomWidth.args = {
variant: 'basic',
label: 'Texbox with a label',
tooltip: 'Some helpful imformation about this feild.',
placeholder: 'Input some text',
width: '300px'
};
8 changes: 6 additions & 2 deletions src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export enum LablePosition {
export type InputProps = {
variant: InputVariant;
margin?: string;
width?: string;
id?: string;
name?: string;
type?: 'text' | 'password' | 'email';
Expand Down Expand Up @@ -105,6 +106,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
const {
variant,
margin,
width,
type,
label,
labelPosition = LablePosition.Top,
Expand All @@ -116,6 +118,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
disabled,
readOnly,
iconPosition,
inputRef,
...props
} = inputProps;

Expand Down Expand Up @@ -155,7 +158,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(

return (
<Flex
width="fit-content"
width={width ? width : "fit-content"}
variant="basic"
align={labelPosition === LablePosition.Left ? 'center' : 'start'}
dir={labelPosition === LablePosition.Left ? 'row' : 'column'}
Expand Down Expand Up @@ -185,6 +188,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
)}
</Box>
<InputWrapper
width="100%"
variant="raw"
align="center"
cols={`${icon ? 'auto ' : ''}1fr${unit ? ' auto' : ''}`}
Expand All @@ -196,7 +200,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
(!iconPosition || iconPosition === IconPosition.Left) &&
renderIcon(icon, iconPosition, disabled)}
<InputComponent
ref={ref}
{...(inputRef ? inputRef : {ref})}
as={isAmount ? NumberInput : 'input'}
{...componentProps}
/>
Expand Down
69 changes: 69 additions & 0 deletions src/components/SidePanel/SidePanel.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { ComponentProps } from 'react';
import { Story } from '@storybook/react';
import { polyIcons } from '../../theme'

import { SidePanel } from './SidePanel';

export default {
title: 'Polyblocks/SidePanel',
component: SidePanel,
};

const Template: Story<ComponentProps<typeof SidePanel>> = (props: any) => (
<SidePanel {...props} />
);

export const Basic = Template.bind({});
Basic.args = {
items: [
{
icon: polyIcons.OfficeBuilding,
text: 'My Companies',
isActive: true,
onClick: () => {}
},
{
icon: polyIcons.PdfBox,
text: 'Dashboard',
onClick: () => {}
},
{
icon: polyIcons.Rocket,
text: 'My offerings',
onClick: () => {}
},
{
icon: polyIcons.FileDocumentOutline,
text: 'Cap table',
onClick: () => {}
}
]
};

export const Expanded = Template.bind({});
Expanded.args = {
items: [
{
icon: polyIcons.OfficeBuilding,
text: 'My Companies',
isActive: true,
onClick: () => {}
},
{
icon: polyIcons.PdfBox,
text: 'Dashboard',
onClick: () => {}
},
{
icon: polyIcons.Rocket,
text: 'My offerings',
onClick: () => {}
},
{
icon: polyIcons.FileDocumentOutline,
text: 'Cap table',
onClick: () => {}
}
],
isExpanded: true
};
67 changes: 67 additions & 0 deletions src/components/SidePanel/SidePanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { ComponentType, PropsWithChildren } from 'react';
import styled from 'styled-components';
import { Flex } from '../Flex';
import { Icon } from '../Icon';
import { Text } from '../Text';

export type SidePanelVariant = 'default';

export type SidePanelItem = {
text: string;
icon: ComponentType;
onClick: (event: React.MouseEvent<HTMLElement>) => void;
isActive?: boolean;
}

export type SidePanelProps = PropsWithChildren<{
items: SidePanelItem[],
isExpanded?: boolean;
}>;

const Component = styled(Flex)<any>(({ theme, isExpanded }) => ({
...(theme.SIDE_PANEL.parent || {}),
...(isExpanded && { width: '240px' })
}));

const StyledFlex = styled(Flex)<any>(({ theme, isActive, isExpanded }) => ({
...(theme.SIDE_PANEL.item || {}),
...(isActive && {
background: theme.COLOR.brandLightest,
svg: {
minWidth: '18px',
path: {
fill: theme.COLOR.brandMain
}
}
}),
'.item-text': {
...theme.SIDE_PANEL.item['.item-text'],
...(isActive && { p: { color: theme.COLOR.brandMain } }),
...(isExpanded && { width: 'fit-content' })
}
}));


const Item = ({ item, isExpanded }: {item: SidePanelItem, isExpanded?: boolean }) => {
return (
<StyledFlex isExpanded={isExpanded} onClick={(e: React.MouseEvent<HTMLElement>) => item.onClick(e)} isActive={item.isActive} variant="raw" >
<Icon size="18px" variant="basic" icon={item.icon} />
<div className="item-text" >
<Text as="p" margin='0 0 0 19px' variant="b1m">{item.text}</Text>
</div>
</StyledFlex>
);
}


export function SidePanel(sidePanelProps: SidePanelProps) {
const { items, isExpanded } = sidePanelProps;

return (
<Component isExpanded={isExpanded} dir="column" >
{
items.map(item => <Item isExpanded={isExpanded} item={item} />)
}
</Component>
);
}
1 change: 1 addition & 0 deletions src/components/SidePanel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './SidePanel';
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ export * from './components/TabBar';
export * from './components/Table';
export * from './components/ProfilePicture';
export * from './components/SelectCard';
export * from './components/SidePanel';
export * from './components/Notification';
Loading