Skip to content

Commit

Permalink
fix: updated input and chip components
Browse files Browse the repository at this point in the history
  • Loading branch information
RichEwin committed Aug 24, 2023
1 parent ef96f7b commit 226b8df
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/components/Chip/Chip.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { StyledChipContainer, StyledChipGroupContainer } from "./Chip.styled";

export interface ChipProps {
Expand All @@ -18,11 +18,18 @@ const Chip = ({ label, active, onClick }: ChipProps) => {
export interface ChipGroupInterface {
tags: string[];
onClick: (tag: string) => void;
reset?: boolean;
}

export const ChipGroup = ({ tags, onClick }: ChipGroupInterface) => {
export const ChipGroup = ({ tags, onClick, reset }: ChipGroupInterface) => {
const [activeTag, setActiveTag] = useState<string | null>(null);

useEffect(() => {
if (reset) {
setActiveTag(null);
}
}, [reset]);

const toggleTag = (tag: string) => {
if (activeTag === tag) {
setActiveTag(null);
Expand Down
4 changes: 4 additions & 0 deletions src/components/Input/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export const WithOnChange = () => (
);

export const WithPlaceholder = () => <Input placeholder="Placeholder" />;

export const WithType = () => <Input type="number" />;

export const WithLabel = () => <Input label="Label" />;
5 changes: 5 additions & 0 deletions src/components/Input/Input.styled.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import styled from "styled-components";

export const StyledInput = styled.input``;
export const LabelWrapper = styled.label`
display: block;
margin-bottom: 8px;
font-weight: bold;
`;
22 changes: 15 additions & 7 deletions src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import React from "react";
import { StyledInput } from "./Input.styled";
import { LabelWrapper, StyledInput } from "./Input.styled";

export interface InputProps {
disabled?: boolean;
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
placeholder?: string;
className?: string;
type?: string;
label?: string;
}

export const Input = ({
disabled,
onChange,
placeholder,
className,
type,
label,
}: InputProps) => {
return (
<StyledInput
disabled={disabled}
onChange={onChange}
placeholder={placeholder}
className={className}
/>
<>
{label ? <LabelWrapper>{label}</LabelWrapper> : null}
<StyledInput
disabled={disabled}
onChange={onChange}
placeholder={placeholder}
className={className}
type={type}
/>
</>
);
};

Expand Down

0 comments on commit 226b8df

Please sign in to comment.