Skip to content
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

Support spread attrs #335

Merged
merged 2 commits into from
Aug 11, 2023
Merged
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
11 changes: 5 additions & 6 deletions src/components/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import React from 'react';
import styled from 'styled-components';
import { gray7, gray9, radiusL } from '@taskany/colors';

interface BadgeProps {
interface BadgeProps extends React.HTMLAttributes<HTMLDivElement> {
children: React.ReactNode;
size?: 's' | 'm';
color?: string;
children: React.ReactNode;
className?: string;

onClick?: React.MouseEventHandler<HTMLDivElement>;
}

Expand Down Expand Up @@ -38,10 +39,8 @@ const StyledBadge = styled.div<{ size: BadgeProps['size']; color?: BadgeProps['c
}
`;

export const Badge: React.FC<BadgeProps> = ({ size = 's', children, className, onClick }) => (
<StyledBadge className={className} size={size} onClick={onClick}>
export const Badge: React.FC<BadgeProps> = ({ size = 's', children, ...props }) => (
<StyledBadge size={size} {...props}>
{children}
</StyledBadge>
);

export default Badge;
2 changes: 0 additions & 2 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,5 +331,3 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
);
},
);

export default Button;
2 changes: 0 additions & 2 deletions src/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ export const Card = styled.div`
border: 1px solid ${gray4};
border-radius: ${radiusM};
`;

export default Card;
2 changes: 0 additions & 2 deletions src/components/CardActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ export const CardActions = styled.div`
left: 0;
padding: 20px 12px 10px;
`;

export default CardActions;
2 changes: 0 additions & 2 deletions src/components/CardComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ export const CardComment = styled.div`
padding: 12px 14px 12px;
user-select: auto;
`;

export default CardComment;
2 changes: 0 additions & 2 deletions src/components/CardContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ export const CardContent = styled.div`
box-sizing: border-box;
padding: 12px 14px;
`;

export default CardContent;
8 changes: 3 additions & 5 deletions src/components/CardInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ const StyledCardInfo = styled(Text)`
border-top-right-radius: ${radiusM};
`;

interface CardInfoProps {
interface CardInfoProps extends React.HTMLAttributes<HTMLDivElement> {
className?: string;
children?: React.ReactNode;
onClick?: (e?: React.MouseEvent<HTMLDivElement>) => void;
}

export const CardInfo: React.FC<CardInfoProps> = ({ className, children, onClick }) => (
<StyledCardInfo className={className} size="xs" weight="bold" color={gray8} onClick={onClick}>
export const CardInfo: React.FC<CardInfoProps> = ({ children, ...props }) => (
<StyledCardInfo size="xs" weight="bold" color={gray8} {...props}>
{children}
</StyledCardInfo>
);

export default CardInfo;
10 changes: 4 additions & 6 deletions src/components/CircleProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';
import { brandColor, gray5 } from '@taskany/colors';
import styled from 'styled-components';

import Text from './Text';
import { Text } from './Text';

interface CircleProgressBarProps {
interface CircleProgressBarProps extends React.HTMLAttributes<HTMLSpanElement> {
value: number;
size?: 's' | 'm' | 'l';
className?: string;
Expand Down Expand Up @@ -41,7 +41,7 @@ const StyledCircle = styled.circle`
transition: stroke-dasharray, stroke-dashoffset 100ms ease-in-out;
`;

export const CircleProgressBar: React.FC<CircleProgressBarProps> = ({ value, size = 'm', className }) => {
export const CircleProgressBar: React.FC<CircleProgressBarProps> = ({ value, size = 'm', ...props }) => {
const diameter = sizeMap[size];
const strokeWidth = size === 's' ? 2 : 3;
const radius = diameter / 2;
Expand All @@ -51,7 +51,7 @@ export const CircleProgressBar: React.FC<CircleProgressBarProps> = ({ value, siz
const offset = circumReference - (value / 100) * circumReference;

return (
<StyledCircleProgressBar className={className}>
<StyledCircleProgressBar {...props}>
<StyledCircleProgressBarAligner>
<StyledCircleProgressBarValue>
<Text weight="bold" color={brandColor} size={size === 'l' ? 'xs' : 'xxs'} as="span">
Expand Down Expand Up @@ -82,5 +82,3 @@ export const CircleProgressBar: React.FC<CircleProgressBarProps> = ({ value, siz
</StyledCircleProgressBar>
);
};

export default CircleProgressBar;
10 changes: 2 additions & 8 deletions src/components/CleanButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import styled from 'styled-components';
import { gray10, gray7, gray8 } from '@taskany/colors';

interface CleanButtonProps {
export interface CleanButtonProps extends React.HTMLAttributes<HTMLDivElement> {
className?: string;

onClick?: (e: React.MouseEvent) => void;
Expand Down Expand Up @@ -35,10 +35,4 @@ const StyledCleanButton = styled.div`
}
`;

export const CleanButton: React.FC<CleanButtonProps> = ({ className, onClick }) => (
<StyledCleanButton className={className} onClick={onClick}>
+
</StyledCleanButton>
);

export default CleanButton;
export const CleanButton: React.FC<CleanButtonProps> = (props) => <StyledCleanButton {...props}>+</StyledCleanButton>;
6 changes: 3 additions & 3 deletions src/components/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface ComboBoxItemProps {
onClick: (value?: any) => void;
}

interface ComboBoxProps {
interface ComboBoxProps extends React.HTMLAttributes<HTMLDivElement> {
renderInput: (props: ComboBoxInputProps) => React.ReactNode;
renderItem: (props: ComboBoxItemProps) => React.ReactNode | Record<any, any>;
renderTrigger?: (props: ComboBoxTriggerProps) => React.ReactNode;
Expand Down Expand Up @@ -98,6 +98,7 @@ export const ComboBox = forwardRef<HTMLDivElement, ComboBoxProps>(
onChange,
onClose,
onClickOutside,
...attrs
},
ref,
) => {
Expand Down Expand Up @@ -207,6 +208,7 @@ export const ComboBox = forwardRef<HTMLDivElement, ComboBoxProps>(
minWidth={minWidth}
maxWidth={maxWidth}
offset={offset}
{...attrs}
>
<div ref={popupContentRef} {...onESC}>
{renderItems ? renderItems(children as React.ReactNode) : (children as React.ReactNode)}
Expand All @@ -216,5 +218,3 @@ export const ComboBox = forwardRef<HTMLDivElement, ComboBoxProps>(
);
},
);

export default ComboBox;
4 changes: 1 addition & 3 deletions src/components/Dot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { colorPrimary, danger9, gray5, warn0 } from '@taskany/colors';

type ViewType = 'default' | 'primary' | 'warning' | 'danger';

interface DotProps {
interface DotProps extends React.HTMLAttributes<HTMLSpanElement> {
size?: 's' | 'm';
view?: ViewType;
}
Expand Down Expand Up @@ -37,5 +37,3 @@ export const Dot = styled.span<DotProps>`
`,
}[size])}
`;

export default Dot;
8 changes: 5 additions & 3 deletions src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { useKeyPress } from '../hooks/useKeyPress';
import { useKeyboard, KeyCode } from '../hooks/useKeyboard';

import { Popup } from './Popup';
import Input from './Input';
import { Input } from './Input';
import { CrossIcon } from './Icon/CrossIcon';
import MenuItem from './MenuItem';
import { MenuItem } from './MenuItem';

interface DropdownTriggerProps {
ref: React.RefObject<HTMLButtonElement>;
Expand All @@ -30,7 +30,7 @@ export interface DropdownItemProps {
onClick: (value?: any) => void;
}

export interface DropdownProps {
export interface DropdownProps extends React.HTMLAttributes<HTMLDivElement> {
renderItem: (props: DropdownItemProps) => React.ReactNode;
renderTrigger: (props: DropdownTriggerProps) => React.ReactNode;
text?: string;
Expand Down Expand Up @@ -88,6 +88,7 @@ export const Dropdown = React.forwardRef<HTMLDivElement, DropdownProps>(
placement = 'bottom-start',
arrow = false,
offset = [-4, 8],
...attrs
},
ref,
) => {
Expand Down Expand Up @@ -195,6 +196,7 @@ export const Dropdown = React.forwardRef<HTMLDivElement, DropdownProps>(
minWidth={100}
maxWidth={250}
offset={offset}
{...attrs}
>
<div {...onESC}>
{nullable(onSearchChange, () => (
Expand Down
8 changes: 3 additions & 5 deletions src/components/Fieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Text } from './Text';

type FieldsetViewType = 'default' | 'warning' | 'danger';

interface FieldsetProps {
interface FieldsetProps extends React.HTMLAttributes<HTMLFieldSetElement> {
title?: string;
view?: FieldsetViewType;
children: React.ReactNode;
Expand All @@ -30,9 +30,9 @@ const colorsMap: Record<FieldsetViewType, string> = {
danger: danger0,
};

export const Fieldset: React.FC<FieldsetProps> = ({ view = 'default', title, children, className }) => {
export const Fieldset: React.FC<FieldsetProps> = ({ view = 'default', title, children, ...props }) => {
return (
<StyledFieldset className={className}>
<StyledFieldset {...props}>
<StyledLegend as="legend" size="m" weight="bold" color={colorsMap[view]}>
{title}
</StyledLegend>
Expand All @@ -41,5 +41,3 @@ export const Fieldset: React.FC<FieldsetProps> = ({ view = 'default', title, chi
</StyledFieldset>
);
};

export default Fieldset;
3 changes: 2 additions & 1 deletion src/components/FiltersContainers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React from 'react';
import styled from 'styled-components';
import { gapM, gapS, gray5, gray6, gray9, radiusXl, textColor } from '@taskany/colors';

import Text from './Text';
import { Text } from './Text';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const FiltersPanelContainer = styled(({ loading, ...props }) => <div {...props} />)<{ loading?: boolean }>`
margin: ${gapM} 0;
padding: ${gapS} 0;
Expand Down
13 changes: 9 additions & 4 deletions src/components/FiltersCounter.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React, { FC } from 'react';
import { textColor } from '@taskany/colors';

import Badge from './Badge';
import Text from './Text';
import { Badge } from './Badge';
import { Text } from './Text';

export const FiltersCounter: FC<{ counter?: number; total: number }> = ({ counter, total }) => (
<Badge size="m">
interface FiltersCounterProps extends React.HTMLAttributes<HTMLDivElement> {
counter?: number;
total: number;
}

export const FiltersCounter: FC<FiltersCounterProps> = ({ counter, total, ...attrs }) => (
<Badge size="m" {...attrs}>
{counter === undefined || total === counter ? (
total
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/components/FiltersDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useCallback, useMemo, useState, ReactNode } from 'react';

import { Dropdown, DropdownItemProps, DropdownProps } from './Dropdown';
import MenuItem from './MenuItem';
import { MenuItem } from './MenuItem';
import { FiltersMenuItem } from './FiltersContainers';

export type FilterDropdownItem<T> = {
Expand All @@ -26,10 +26,10 @@
onSearchChange?: DropdownProps['onSearchChange'];
};

export const FiltersDropdownBase = React.forwardRef<HTMLDivElement, FilterDropdownBaseProps<any>>(

Check warning on line 29 in src/components/FiltersDropdown.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
({ text, type = 'multiselect', disabled, items, value, onChange, renderItem, onSearchChange }, ref) => {
const onChangeHandler = useCallback(
(item: FilterDropdownItem<any>) => {

Check warning on line 32 in src/components/FiltersDropdown.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
const existedIndex = value.indexOf(item.id);

if (type === 'single') {
Expand Down
12 changes: 5 additions & 7 deletions src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components';
import { gray0 } from '@taskany/colors';

import { SheepLogo } from './SheepLogo';
import Text from './Text';
import { Text } from './Text';

const StyledFooter = styled.footer`
display: grid;
Expand All @@ -19,19 +19,17 @@ const StyledFooterMenu = styled.div`
export const FooterItem = styled(Text)`
padding: 0px 10px;
`;
interface FooterProps {
className?: string;
interface FooterProps extends React.HTMLAttributes<HTMLDivElement> {
children: React.ReactNode;
className?: string;
}

export const Footer: React.FC<FooterProps> = ({ className, children }) => {
export const Footer: React.FC<FooterProps> = ({ className, children, ...attrs }) => {
return (
<StyledFooter className={className}>
<StyledFooter className={className} {...attrs}>
<Text color={gray0}>{`© ${new Date().getFullYear()} Taskany, Inc.`}</Text>
<StyledFooterMenu>{children}</StyledFooterMenu>
<SheepLogo />
</StyledFooter>
);
};

export default Footer;
8 changes: 3 additions & 5 deletions src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { gray3 } from '@taskany/colors';
import { KeyCode, KeyMod, useKeyboard } from '../hooks/useKeyboard';
import { formContext } from '../context/form';

interface FormProps {
interface FormProps extends React.HTMLAttributes<HTMLFormElement> {
children: React.ReactNode;
disabled?: boolean;
submitHotkey?: Array<number>;
Expand All @@ -19,7 +19,7 @@ const StyledForm = styled.form`
background-color: ${gray3};
`;

export const Form: React.FC<FormProps> = ({ children, disabled, submitHotkey = submitKeys, onSubmit }) => {
export const Form: React.FC<FormProps> = ({ children, disabled, submitHotkey = submitKeys, onSubmit, ...attrs }) => {
const handleSubmit = (e?: React.SyntheticEvent) => {
e?.preventDefault();

Expand All @@ -33,11 +33,9 @@ export const Form: React.FC<FormProps> = ({ children, disabled, submitHotkey = s

return (
<formContext.Provider value={{ disabled }}>
<StyledForm {...keyboard} onSubmit={handleSubmit}>
<StyledForm {...keyboard} onSubmit={handleSubmit} {...attrs}>
{children}
</StyledForm>
</formContext.Provider>
);
};

export default Form;
2 changes: 0 additions & 2 deletions src/components/FormAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,3 @@ export const FormAction = styled.div<{ left?: boolean; right?: boolean; columns?
}
`}
`;

export default FormAction;
2 changes: 0 additions & 2 deletions src/components/FormActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,3 @@ export const FormActions = styled(({ flat, focused, ...props }: FormActionsProps
border-bottom-right-radius: 0;
`}
`;

export default FormActions;
2 changes: 0 additions & 2 deletions src/components/FormCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ export const FormCard = styled.div`
border: 1px solid ${gray4};
border-radius: ${radiusM};
`;

export default FormCard;
Loading
Loading