Skip to content

Commit

Permalink
Merge pull request #328 from ebs-integrator/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
devdfan authored Sep 6, 2021
2 parents 19e35cf + 284a2aa commit f4766b2
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 70 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ebs-design",
"version": "0.0.1-beta.102",
"version": "0.0.1-beta.103",
"description": "EBS Design System React UI elements.",
"author": "EBS Integrator <[email protected]> (https://ebs-integrator.com/)",
"maintainers": [
Expand Down
3 changes: 3 additions & 0 deletions src/components/atoms/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const Avatar: React.FC<AvatarProps> = ({
shortLetters,
alt = '',
img,
children,
status,
...props
}) => {
Expand All @@ -47,6 +48,8 @@ export const Avatar: React.FC<AvatarProps> = ({
<div className="ebs-avatar__short-alt">{shortAlt}</div>
)}

{children}

{status ? <div className={`ebs-avatar__status ebs-avatar__status--${status}`} /> : null}
</div>
);
Expand Down
12 changes: 12 additions & 0 deletions src/components/atoms/Button/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@
padding: rem($btn-padding-y-lg $btn-padding-x-lg);
font-weight: $btn-font-weight-lg;
font-size: rem($btn-font-size-lg);

&.ebs-button--is-icon {
padding: rem($btn-padding-y-lg);
}
}

&--medium {
Expand All @@ -226,6 +230,10 @@
padding: rem($btn-padding-y $btn-padding-x);
font-weight: $btn-font-weight;
font-size: rem($btn-font-size);

&.ebs-button--is-icon {
padding: rem($btn-padding-y);
}
}

&--small {
Expand All @@ -237,6 +245,10 @@
font-weight: $btn-font-weight-sm;
font-size: rem($btn-font-size-sm);
line-height: rem($btn-line-height-sm);

&.ebs-button--is-icon {
padding: rem($btn-padding-y-sm);
}
}

&__wrapper {
Expand Down
11 changes: 9 additions & 2 deletions src/components/atoms/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ButtonProps extends Omit<Omit<React.ButtonHTMLAttributes<HTMLBu
submit?: boolean;
buttonClass?: string;
form?: string;
icon?: string;
icon?: any;
block?: boolean;
round?: boolean;
}
Expand Down Expand Up @@ -66,7 +66,14 @@ export const Button: React.FC<ButtonProps> = ({
disabled={props.disabled || loading}
{...props}
>
{icon ? <Icon type={icon} /> : props.children}
{icon ? (
<Icon
component={typeof icon !== 'string' ? icon : undefined}
type={typeof icon === 'string' ? icon : undefined}
/>
) : (
props.children
)}
</button>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/atoms/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export const Regular = (): React.ReactNode => {
return Object.keys(icons[model]).map((icon) => {
const iconName = `<Icon type="${icon}" ${model === 'bold' ? 'model="bold"' : ''} />`;

const onCopy = (): void => {
copyToClipboard(iconName);
const onCopy = async (): Promise<void> => {
await copyToClipboard(iconName);
onCopied();
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/Input/Input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
}
}

&.ebs-input__style-grey {
&.ebs-input-style--grey {
background-color: $grey-50;
}

Expand Down
8 changes: 4 additions & 4 deletions src/components/atoms/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
`ebs-input__wrapper`,
`ebs-input__wrapper--${hasValue ? `active` : `unactive`}`,
`ebs-input__type--${type}`,
`ebs-input-style-${styleType}`,
`ebs-input-style--${styleType}`,
className,
{
'ebs-input__empty': value === '',
Expand All @@ -104,16 +104,16 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
className={cn(`ebs-input__prefix`, !loading && props.onClickPrefix ? `clickable` : `not-clickable`)}
onClick={onClickPrefixHandler}
>
{loading ? <Loader.Spinner size="small" /> : prefix}
{loading && !suffix ? <Loader.Spinner size="small" /> : prefix}
</div>
) : null}

{suffix ? (
{loading || suffix ? (
<div
className={cn(`ebs-input__suffix`, !loading && props.onClickSuffix ? `clickable` : `not-clickable`)}
onClick={onClickSuffixHandler}
>
{loading && !prefix ? <Loader.Spinner size="small" /> : suffix}
{loading && (!prefix || (prefix && suffix)) ? <Loader.Spinner size="small" /> : suffix}
</div>
) : null}

Expand Down
12 changes: 10 additions & 2 deletions src/components/atoms/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface TabsComposition {

export interface TabsProps extends React.HTMLAttributes<HTMLDivElement> {
activeTab?: string;
contentClass?: string;
setActiveTab?: (key: string) => void;
}

Expand All @@ -20,7 +21,14 @@ export interface TabsContext {

const TabsContext = React.createContext<TabsContext | undefined>(undefined);

const Tabs: React.FC<TabsProps> & TabsComposition = ({ activeTab, setActiveTab, className, children, ...props }) => {
const Tabs: React.FC<TabsProps> & TabsComposition = ({
activeTab,
setActiveTab,
className,
contentClass,
children,
...props
}) => {
const memoizedContextValue = React.useMemo(
() => ({
activeTab,
Expand All @@ -39,7 +47,7 @@ const Tabs: React.FC<TabsProps> & TabsComposition = ({ activeTab, setActiveTab,
}
})}
</div>
<div className={`ebs-tabs__content`}>
<div className={cn(`ebs-tabs__content`, contentClass)}>
{children &&
React.Children.map(children, (child) => {
if (child && (child as React.ReactElement).type !== Tab) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ import type { ReactDatePickerProps } from 'react-datepicker';
import { omitKeys } from 'libs';
import { getOutputDate } from '../utils';

const keysToOmit = ['autoComplete', 'autoFocus', 'dateFormat', 'endDate', 'startDate', 'value'];
const keysToOmit: (keyof ReactDatePickerProps)[] = [
'autoComplete',
'autoFocus',
'dateFormat',
'endDate',
'startDate',
'value',
];

const CustomRangeInput = React.forwardRef<HTMLInputElement, Partial<ReactDatePickerProps>>((props, ref) => {
const range = [getOutputDate(props.startDate, props.dateFormat), getOutputDate(props.endDate, props.dateFormat)];
const value = range.filter((r) => !r).length === range.length ? '' : range.join(' - ');

return <input ref={ref} {...omitKeys(keysToOmit, props)} title={value} value={value} />;
return <input ref={ref} {...omitKeys(props, keysToOmit)} title={value} value={value} />;
});

export default CustomRangeInput;
2 changes: 1 addition & 1 deletion src/components/organisms/Table/Table.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import '~rc-table/assets/index.css';

.ebs-table {
.rc-table.ebs-table {
box-shadow: $table-box-shadow;

// FIXME: Fix table on mobile
Expand Down
8 changes: 5 additions & 3 deletions src/libs/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export const validate = (errors: string[] | { [key: string]: string[] }): string
return [];
};

export const isObject = (val: any): boolean => typeof val === 'object';
export const isObject = (val: any): boolean => typeof val === 'object' && val !== null;

export const omitKeys = (keys: string[], obj: object): object => {
export const omitKeys = <T extends object, K extends Extract<keyof T, string>>(obj: T, keys: K[]): Omit<T, K> => {
const updatedObj = { ...obj };

for (const n of keys) delete updatedObj[n];
for (const key of keys) {
delete updatedObj[key];
}

return updatedObj;
};
24 changes: 17 additions & 7 deletions src/libs/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ export const firstLetters = (target: string, count = 1): string =>
.substr(0, count)
: '';

export const copyToClipboard = (str: string): void => {
const el = document.createElement('textarea');
export const copyToClipboard = (str: string): Promise<void> => {
if (navigator.clipboard) {
try {
return navigator.clipboard.writeText(str);
} catch (err) {}
}

return Promise.resolve(deprecatedCopyToClipboard(str));

el.value = str;
document.body.appendChild(el);
function deprecatedCopyToClipboard(str: string): void {
const el = document.createElement('textarea');

el.select();
el.value = str;
document.body.appendChild(el);

document.execCommand('copy');
document.body.removeChild(el);
el.select();

document.execCommand('copy');
document.body.removeChild(el);
}
};
13 changes: 0 additions & 13 deletions src/resources/svg/cursor-default.svg

This file was deleted.

16 changes: 0 additions & 16 deletions src/resources/svg/cursor-pointer.svg

This file was deleted.

12 changes: 0 additions & 12 deletions src/resources/svg/cursor-text.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/resources/svg/error.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/resources/svg/example.svg

This file was deleted.

0 comments on commit f4766b2

Please sign in to comment.