Skip to content

Commit

Permalink
Change name dropdown, fix url validate (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaltoroc authored Jan 10, 2024
1 parent 63c371f commit d615d5d
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 72 deletions.
25 changes: 20 additions & 5 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
<!-- markdownlint-configure-file { "MD024": { "allow_different_nesting": true } } -->
# Changelog

## v0.0.5 - DropDown (Jan 2 - 2021)
## v0.2.0 - Checkbox (Jan 10 - 2024)

### 👾 Feature

- Checkbox
- Fix name Dropdown
- Fix build chromatic
- New util isValidUrl

## v0.1.0 - Avatar (Jan 3 - 2024)

### 👾 Feature

- Avatar

## v0.0.5 - Dropdown (Jan 2 - 2024)

### 🐛 Bugs

- DropDown - Label default value
- Dropdown - Label default value
- Storybook config
- Changelog - Version in Storybook

## v0.0.4 - DropDown (Jan 2 - 2021)
## v0.0.4 - Dropdown (Jan 2 - 2021)

### 🐛 Bugs

- PerDependencies
- Update Readme.md
- Types Controller React Hook Form

## v0.0.3 - DropDown (Dec 21 - 2023)
## v0.0.3 - Dropdown (Dec 21 - 2023)

### 👾 Feature

- DropDown
- Dropdown

### 🐛 Bugs

Expand Down
10 changes: 5 additions & 5 deletions src/types/helpers/controller.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import type {
ControllerProps as RHFControllerProps
} from 'react-hook-form';

import { DropDown, TextBox } from '@/ui/forms';
import { Dropdown, TextBox } from '@/ui/forms';

type TextBoxType = {
as: typeof TextBox;
} & React.ComponentProps<typeof TextBox>;

type DropDownType = {
as: typeof DropDown;
} & React.ComponentProps<typeof DropDown>;
type DropdownType = {
as: typeof Dropdown;
} & React.ComponentProps<typeof Dropdown>;

type Inputs = TextBoxType | DropDownType;
type Inputs = TextBoxType | DropdownType;

export type ControllerType<
TFieldValues extends FieldValues = FieldValues,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TextBoxType } from './text-box.types';

export interface DropDownOption {
export interface DropdownOption {
value: string | number;
label: string;
}

export interface DropDownType extends TextBoxType {
options?: DropDownOption[];
export interface DropdownType extends TextBoxType {
options?: DropdownOption[];
onChange?: (option: React.ChangeEvent<HTMLInputElement>) => void;
onTextChange?: (text?: string) => void;
}
2 changes: 1 addition & 1 deletion src/types/ui/forms/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type * from './checkbox.types';
export type * from './drop-down.types';
export type * from './dropdown.types';
export type * from './text-box.types';
4 changes: 2 additions & 2 deletions src/ui/components/avatar/avatar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useMemo } from 'react';
import cls from 'classnames';

import type { AvatarType } from '@/types';
import { getInitials } from '@/utils';
import { getInitials, isValidUrl } from '@/utils';

const Avatar = ({
isOnline = false,
Expand All @@ -12,7 +12,7 @@ const Avatar = ({
src,
withStatus = false
}: AvatarType) => {
const isUri = useMemo(() => URL.canParse(src), [src]);
const isUri = useMemo(() => isValidUrl(src), [src]);

const letters = useMemo(() => getInitials(src), [src, isUri]);

Expand Down
3 changes: 1 addition & 2 deletions src/ui/components/avatar/avatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ const meta: Meta<typeof Avatar> = {
description: 'Size',
type: 'string',
options: ['xs', 'sm', 'md', 'lg'],
control: { type: 'select' },
defaultValue: 'md'
control: { type: 'select' }
}
},
args: {
Expand Down
3 changes: 0 additions & 3 deletions src/ui/forms/drop-down/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<DropDown /> snapshot 1`] = `
exports[`<Dropdown /> snapshot 1`] = `
<div>
<div
class="dropdown block"
Expand Down Expand Up @@ -39,7 +39,7 @@ exports[`<DropDown /> snapshot 1`] = `
</div>
`;

exports[`<DropDown /> snapshot full 1`] = `
exports[`<Dropdown /> snapshot full 1`] = `
<div>
<div
class="dropdown block"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { FaSortDown } from 'react-icons/fa';
import { useOnClickOutside } from 'usehooks-ts';

import { TextBox } from '@/ui/forms';
import type { DropDownOption, DropDownType, TextBoxRef } from '@/types';
import type { DropdownOption, DropdownType, TextBoxRef } from '@/types';

const DropDown = forwardRef<TextBoxRef, DropDownType>(
const Dropdown = forwardRef<TextBoxRef, DropdownType>(
(
{
name,
Expand Down Expand Up @@ -68,7 +68,7 @@ const DropDown = forwardRef<TextBoxRef, DropDownType>(
}, [open, disabled]);

const handleSelect = useCallback(
(option: DropDownOption) => {
(option: DropdownOption) => {
onChange?.({
target: { value: String(option.value) }
} as React.ChangeEvent<HTMLInputElement>);
Expand Down Expand Up @@ -136,4 +136,4 @@ const DropDown = forwardRef<TextBoxRef, DropDownType>(
}
);

export default DropDown;
export default Dropdown;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Meta, StoryObj } from '@storybook/react';
import * as Icons from 'react-icons/fa';

import DropDown from './drop-down.component';
import Dropdown from './dropdown.component';

const meta: Meta<typeof DropDown> = {
title: '@creativecodeco-ui/Form/DropDown',
component: DropDown,
const meta: Meta<typeof Dropdown> = {
title: '@creativecodeco-ui/Form/Dropdown',
component: Dropdown,
argTypes: {
name: {
description: 'Unique Name',
Expand All @@ -16,7 +16,7 @@ const meta: Meta<typeof DropDown> = {
type: 'string'
},
isError: {
description: 'DropDown has error',
description: 'Dropdown has error',
type: 'boolean'
},
error: {
Expand All @@ -31,8 +31,7 @@ const meta: Meta<typeof DropDown> = {
description: 'Size',
type: 'string',
options: ['xs', 'sm', 'md', 'lg'],
control: { type: 'select' },
defaultValue: 'md'
control: { type: 'select' }
},
leftIcon: {
description: 'Left Icon',
Expand All @@ -45,7 +44,7 @@ const meta: Meta<typeof DropDown> = {
}
},
args: {
name: 'drop-down',
name: 'dropdown',
size: 'md',
options: Array.from({ length: 10 }).map((_, index) => ({
value: index.toString(),
Expand All @@ -56,7 +55,9 @@ const meta: Meta<typeof DropDown> = {

export default meta;

type Story = StoryObj<typeof DropDown>;
Dropdown.displayName = 'Dropdown';

type Story = StoryObj<typeof Dropdown>;

export const Primary: Story = {
args: {}
Expand All @@ -72,7 +73,7 @@ export const WithError: Story = {
args: {
label: 'Label',
isError: true,
error: 'Error DropDown'
error: 'Error Dropdown'
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { fireEvent, render, screen } from '@testing-library/react';

import DropDown from './drop-down.component';
import Dropdown from './dropdown.component';

import type { DropDownOption } from '@/types';
import type { DropdownOption } from '@/types';

const options = Array.from({ length: 5 }).map<DropDownOption>((_, index) => ({
const options = Array.from({ length: 5 }).map<DropdownOption>((_, index) => ({
value: index,
label: `Option ${index}`
}));

describe('<DropDown />', () => {
describe('<Dropdown />', () => {
it('snapshot', () => {
const { container } = render(<DropDown name='test' />);
const { container } = render(<Dropdown name='test' />);

expect(container).toMatchSnapshot();
});

it('snapshot full', () => {
const { container } = render(
<DropDown name='test' label='Label' isError error='Error' disabled />
<Dropdown name='test' label='Label' isError error='Error' disabled />
);

expect(container).toMatchSnapshot();
});

it('default value', () => {
const { getByTestId } = render(
<DropDown name='test' options={options} value='2' />
<Dropdown name='test' options={options} value='2' />
);

const control = getByTestId('test');
Expand All @@ -35,7 +35,7 @@ describe('<DropDown />', () => {
});

it('focus', () => {
const { getByTestId } = render(<DropDown name='test' options={options} />);
const { getByTestId } = render(<Dropdown name='test' options={options} />);

const textBox = getByTestId('test');

Expand All @@ -46,7 +46,7 @@ describe('<DropDown />', () => {

it('focus disabled', async () => {
const { getByTestId } = render(
<DropDown name='test' options={options} disabled />
<Dropdown name='test' options={options} disabled />
);

const textBox = getByTestId('test');
Expand All @@ -61,7 +61,7 @@ describe('<DropDown />', () => {
const onChangeMock = jest.fn();

const { getByTestId, getByText } = render(
<DropDown name='test' options={options} onChange={onChangeMock} />
<Dropdown name='test' options={options} onChange={onChangeMock} />
);

const textBox = getByTestId('test');
Expand All @@ -77,7 +77,7 @@ describe('<DropDown />', () => {

it('closes the dropdown on click outside', () => {
const { getByTestId } = render(
<DropDown name='test' data-testid='textbox' options={options} />
<Dropdown name='test' data-testid='textbox' options={options} />
);

const textBox = getByTestId('textbox');
Expand All @@ -103,7 +103,7 @@ describe('<DropDown />', () => {
it('handles change correctly', () => {
const onTextChangeMock = jest.fn();
const { getByTestId } = render(
<DropDown name='test' onTextChange={onTextChangeMock} options={options} />
<Dropdown name='test' onTextChange={onTextChangeMock} options={options} />
);
const textBox = getByTestId('test');

Expand All @@ -115,7 +115,7 @@ describe('<DropDown />', () => {
it('handles change correctly with option', () => {
const onTextChangeMock = jest.fn();
const { getByTestId } = render(
<DropDown name='test' onTextChange={onTextChangeMock} options={options} />
<Dropdown name='test' onTextChange={onTextChangeMock} options={options} />
);
const textBox = getByTestId('test');

Expand Down
3 changes: 3 additions & 0 deletions src/ui/forms/dropdown/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Dropdown from './dropdown.component';

export { Dropdown };
2 changes: 1 addition & 1 deletion src/ui/forms/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from '@/ui/forms/checkbox';
export * from '@/ui/forms/drop-down';
export * from '@/ui/forms/dropdown';
export * from '@/ui/forms/text-box';
5 changes: 3 additions & 2 deletions src/ui/forms/text-box/text-box.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const meta: Meta<typeof TextBox> = {
description: 'Size',
type: 'string',
options: ['xs', 'sm', 'md', 'lg'],
control: { type: 'select' },
defaultValue: 'md'
control: { type: 'select' }
},
leftIcon: {
description: 'Left Icon',
Expand Down Expand Up @@ -65,6 +64,8 @@ const meta: Meta<typeof TextBox> = {

export default meta;

TextBox.displayName = 'TextBox';

type Story = StoryObj<typeof TextBox>;

export const Primary: Story = {
Expand Down
Loading

0 comments on commit d615d5d

Please sign in to comment.