Skip to content

Commit

Permalink
fix: token components lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kyhyco committed Jun 14, 2024
1 parent b51ce9b commit 9f2e5bb
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/token/components/SearchIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export function SearchIcon() {
return (
<svg
role="img"
aria-label="ock-search-icon"
width="16"
height="16"
viewBox="0 0 16 16"
Expand Down
14 changes: 10 additions & 4 deletions src/token/components/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ type TextInputReact = {
};

export function TextInput({ placeholder, value, onChange }: TextInputReact) {
const handleChange = useCallback((evt: ChangeEvent<HTMLInputElement>) => {
onChange(evt.target.value);
}, []);
const handleChange = useCallback(
(evt: ChangeEvent<HTMLInputElement>) => {
onChange(evt.target.value);
},
[onChange],
);

const handleClear = useCallback(() => {
onChange('');
}, []);
}, [onChange]);

return (
<div className="relative flex items-center">
Expand All @@ -31,11 +34,14 @@ export function TextInput({ placeholder, value, onChange }: TextInputReact) {
/>
{value && (
<button
type="button"
data-testid="ockTextInput_Clear"
className="-translate-y-1/2 absolute top-1/2 right-4"
onClick={handleClear}
>
<svg
role="img"
aria-label="ock-close-icon"
width="16"
height="16"
viewBox="0 0 16 16"
Expand Down
6 changes: 4 additions & 2 deletions src/token/components/TokenChip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TextBody } from '../../internal/text';
import type { TokenChipReact } from '../types';
import { TokenImage } from './TokenImage';

/**
* Small button that display a given token symbol and image.
Expand All @@ -10,11 +11,12 @@ import type { TokenChipReact } from '../types';
export function TokenChip({ token, onClick }: TokenChipReact) {
return (
<button
type="button"
data-testid="ockTokenChip_Button"
className="flex w-fit items-center rounded-2xl bg-[#eef0f3] py-1 pr-3 pl-1 hover:active:bg-[#bfc1c3] hover:bg-[#cacbce] shrink-0 shadow-[0px_8px_12px_0px_#5B616E1F] "
className='flex w-fit shrink-0 items-center gap-2 rounded-2xl bg-[#eef0f3] py-1 pr-3 pl-1 shadow-[0px_8px_12px_0px_#5B616E1F] hover:active:bg-[#bfc1c3] hover:bg-[#cacbce]'
onClick={() => onClick?.(token)}
>
<img className="mr-2 h-6 w-6" src={token.image || ''} />
<TokenImage token={token} size={24} />
<TextBody>{token.symbol}</TextBody>
</button>
);
Expand Down
3 changes: 2 additions & 1 deletion src/token/components/TokenImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function TokenImage({ className, size = 24, token }: TokenImageReact) {
height: `${size}px`,
},
};
}, [size]);
}, [size, name]);

if (!image) {
return (
Expand All @@ -35,6 +35,7 @@ export function TokenImage({ className, size = 24, token }: TokenImageReact) {
return (
<img
className={className || 'ock-tokenimage'}
alt="token-image"
data-testid="ockTokenImage_Image"
style={styles.image}
src={image}
Expand Down
1 change: 1 addition & 0 deletions src/token/components/TokenRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const TokenRow = memo(function TokenRow({
return (
<button
data-testid="ockTokenRow_Container"
type="button"
className="flex h-16 w-full cursor-pointer items-center justify-between bg-white px-2 py-1 active:bg-[#bfc1c3] hover:bg-[#cacbce]"
onClick={() => onClick?.(token)}
>
Expand Down
19 changes: 11 additions & 8 deletions src/token/components/TokenSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ export function TokenSearch({ onChange, delayMs = 200 }: TokenSearchReact) {
onChange(value);
}, delayMs);

const handleChange = useCallback((value: string) => {
setValue(value);
const handleChange = useCallback(
(value: string) => {
setValue(value);

if (delayMs > 0) {
handleDebounce(value);
} else {
onChange(value);
}
}, []);
if (delayMs > 0) {
handleDebounce(value);
} else {
onChange(value);
}
},
[onChange, handleDebounce, delayMs],
);

return (
<TextInput
Expand Down
5 changes: 5 additions & 0 deletions src/token/components/TokenSelectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ function CaretUp() {
return (
<svg
data-testid="ockTokenSelectButton_CaretUp"
role="img"
aria-label="ock-caretup-icon"
width="16"
height="16"
viewBox="0 0 16 16"
Expand All @@ -25,6 +27,8 @@ function CaretDown() {
return (
<svg
data-testid="ockTokenSelectButton_CaretDown"
role="img"
aria-label="ock-caretdown-icon"
width="16"
height="17"
viewBox="0 0 16 17"
Expand All @@ -45,6 +49,7 @@ export const TokenSelectButton = forwardRef(function TokenSelectButton(
) {
return (
<button
type="button"
data-testid="ockTokenSelectButton_Button"
className="flex w-fit items-center gap-2 rounded-2xl bg-[#eef0f3] px-3 py-1 outline-none active:bg-[#bfc1c3] hover:bg-[#cacbce]"
onClick={onClick}
Expand Down
2 changes: 1 addition & 1 deletion src/token/components/TokenSelectDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function TokenSelectDropdown({
return () => {
document.removeEventListener('click', handleBlur);
};
}, []);
}, [handleBlur]);

return (
<div className={'relative'}>
Expand Down

0 comments on commit 9f2e5bb

Please sign in to comment.