Skip to content

Commit

Permalink
Adjust input styling, AddSocialPlatform Component
Browse files Browse the repository at this point in the history
  • Loading branch information
agjs committed Apr 17, 2024
1 parent 80291a7 commit ca1a289
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@programmer_network/yail",
"version": "1.0.149",
"version": "1.0.150",
"description": "Programmer Network's official UI library for React",
"author": "Aleksandar Grbic - (https://programmer.network)",
"publishConfig": {
Expand Down
79 changes: 79 additions & 0 deletions src/Components/AddSocialPlatform/AddSocialPlatform.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import AddSocialPlatform from ".";

export default {
title: "Components/AddSocialPlatform",
parameters: {
layout: "centered"
},
component: AddSocialPlatform
};

export const Default = () => {
const SOCIAL_PLATFORMS = [
{
name: "Github",
url: "github.com/"
},
{
name: "Gitlab",
url: "gitlab.com/"
},
{
name: "Stackoverflow",
url: "stackoverflow.com/users/"
},
{
name: "Linkedin",
url: "linkedin.com/in/"
},
{
name: "YouTube",
url: "youtube.com/"
},
{
name: "Twitter",
url: "twitter.com/"
},
{
name: "Mastodon",
url: "mastodon.social/"
},
{
name: "Codewars",
url: "codewars.com/users/"
},
{
name: "Patreon",
url: "patreon.com/user?u="
},
{
name: "Hackernews",
url: "news.ycombinator.com/user?id="
},
{
name: "Reddit",
url: "reddit.com/user/"
},
{
name: "Hackerrank",
url: "hackerrank.com/"
},
{
name: "Leetcode",
url: "leetcode.com/"
},
{
name: "Exercism",
url: "exercism.org/profiles/"
}
];

return (
<div>
<AddSocialPlatform
platforms={SOCIAL_PLATFORMS}
onAdd={data => console.log(data)}
/>
</div>
);
};
93 changes: 93 additions & 0 deletions src/Components/AddSocialPlatform/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import useAJVForm from "@programmer_network/use-ajv-form";
import { FC } from "react";

import Button from "Components/Button";
import { IconAdd } from "Components/Icons";
import { Input, Select } from "Components/Inputs";
import { Paragraph } from "Components/Typography";

const AddSocialPlatform: FC<{
platforms: { name: string; url: string }[];
onAdd: (data: Record<string, string>) => void;
}> = ({ onAdd, platforms }) => {
const form = useAJVForm(
{
platform: "",
url: ""
},
{
type: "object",
properties: {
platform: {
type: "string",
minLength: 1,
errorMessage: "Please select a platform"
},
url: {
type: "string",
minLength: 1,
errorMessage: "Please enter a username"
}
},
required: ["platform", "url"]
}
);

return (
<div className='grid grid-cols-12 items-start gap-2 my-4'>
<Select
name='platform'
label='Platform'
onChange={form.set}
inputWrapperClassName='col-span-5'
value={form.state.platform.value}
error={form.state.platform.error}
options={platforms.map(({ name }) => ({
label: name,
value: name
}))}
/>
<div className='col-span-5'>
<Input
name='url'
label='Username'
hint={
<div>
<Paragraph>
Username, a slug or a handle. Different platforms call it
differently.
</Paragraph>
<Paragraph className='text-red-500'>
<span className='font-bold'>Do not</span> include the base URL.
</Paragraph>
</div>
}
value={form.state.url.value}
error={form.state.url.error}
onChange={form.set}
/>
</div>
<Button
outlined
className='col-span-2 mt-8'
onClick={() => {
if (!form.validate().isValid) {
return;
}

onAdd?.({
[form.state.platform.value]: form.state.url.value
});

form.reset();
}}
>
<div className='flex gap-1 items-center'>
<IconAdd className='w-6' />
</div>
</Button>
</div>
);
};

export default AddSocialPlatform;
2 changes: 1 addition & 1 deletion src/Components/Button/__snapshots__/Button.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Button component > renders correctly - snapshot test 1`] = `
<DocumentFragment>
<button
class="select-none border-2 border-primary px-3 py-2 font-semibold uppercase tracking-tight rounded-md bg-primary hover:bg-transparent hover:text-primary hover:fill-primary text-primary-background-color"
class="select-none border-2 border-primary px-3 py-2 font-semibold tracking-tight rounded-md bg-primary hover:bg-transparent hover:text-primary hover:fill-primary text-primary-background-color"
type="button"
>
<div
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Button: React.FC<IButtonProps> = ({
outlined = false
}) => {
let cls =
"select-none border-2 border-primary px-3 py-2 font-semibold uppercase tracking-tight rounded-md ";
"select-none border-2 border-primary px-3 py-2 font-semibold tracking-tight rounded-md ";

if (disabled) {
cls += "cursor-not-allowed opacity-70 ";
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const Dropdown: React.FC<IDropdownProps> = ({
ref={popperRef}
className={classNames(
dropdownClassName,
"absolute z-10 mt-2 w-56 border-2 border-primary-text-color/40 bg-primary-background-color shadow-sm"
"absolute z-50 mt-2 w-56 border-2 border-primary-text-color/40 bg-primary-background-color shadow-sm"
)}
>
{children ? (
Expand Down
6 changes: 3 additions & 3 deletions src/Components/Inputs/Common/InputHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC } from "react";

import CharacterCounter from "Components/CharacterCounter";
import { IconQuestionMark } from "Components/Icons";
import { IconInfo } from "Components/Icons";
import Tooltip from "Components/Tooltip";

import { InputHeaderProps } from "./types";
Expand All @@ -21,10 +21,10 @@ const InputHeader: FC<InputHeaderProps> = ({

return (
<div className='mb-2 flex items-center justify-between'>
<div className='flex items-center gap-1'>
<div className='flex items-center gap-0.5'>
{hint && name && (
<Tooltip text={hint} id={name} place='right'>
<IconQuestionMark className='w-4 text-primary-text-color' />
<IconInfo className='w-4 text-primary-text-color relative top-[1px] cursor-pointer' />
</Tooltip>
)}
<div className='text-primary-text-color'>
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Inputs/Common/InputHeader/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface InputHeaderProps {
value?: string | number;
max?: number;
label?: string;
hint?: string;
hint?: string | React.ReactNode;
type?: string;
required?: boolean;
}
2 changes: 1 addition & 1 deletion src/Components/Inputs/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const Input: FC<IInputProps> = forwardRef<HTMLInputElement, IInputProps>(
return (
<div className={classNames(inputWrapperClassName)}>
<InputHeader {...inputHeaderProps} />
<div className='flex flex-col gap-1'>
<div className='flex flex-col'>
<input
ref={ref}
{...rest}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Inputs/Input/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface IInputProps
max?: number;
children?: React.ReactNode;
minDate?: string;
hint?: string;
hint?: string | React.ReactNode;
className?: string;
disabled?: boolean;
error?: string | string[] | Record<string, string>;
Expand Down
1 change: 1 addition & 0 deletions src/Components/Inputs/Select/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const styles: StylesConfig<Option | undefined, false | true> = {
...base,
outline: "none",
boxShadow: "none",
padding: "4px 0",
color,
"input:focus": {
boxShadow: "none"
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Inputs/Tiptap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const Tiptap: ForwardRefRenderFunction<TiptapRef, TiptapProps> = (
link={link}
/>
)}
<div className='flex flex-col gap-1'>
<div className='flex flex-col'>
<div
className={classNames(
"relative break-all rounded-bl-md rounded-br-md border-2 border-primary-text-color/40 px-4 pb-2 pt-2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`ThemeBuilder component > renders correctly with given props 1`] = `
class="flex gap-1 flex-col md:flex-row"
>
<button
class="select-none border-2 border-primary px-3 py-2 font-semibold uppercase tracking-tight rounded-md bg-transparent text-primary fill-primary hover:bg-primary hover:fill-primary-background-color hover:text-primary-background-color primary-button h-12 min-w-[120px] shadow-none"
class="select-none border-2 border-primary px-3 py-2 font-semibold tracking-tight rounded-md bg-transparent text-primary fill-primary hover:bg-primary hover:fill-primary-background-color hover:text-primary-background-color primary-button h-12 min-w-[120px] shadow-none"
type="button"
>
<div
Expand All @@ -27,7 +27,7 @@ exports[`ThemeBuilder component > renders correctly with given props 1`] = `
</div>
</button>
<button
class="select-none border-2 border-primary px-3 py-2 font-semibold uppercase tracking-tight rounded-md bg-transparent text-primary fill-primary hover:bg-primary hover:fill-primary-background-color hover:text-primary-background-color h-12 min-w-[120px] shadow-none"
class="select-none border-2 border-primary px-3 py-2 font-semibold tracking-tight rounded-md bg-transparent text-primary fill-primary hover:bg-primary hover:fill-primary-background-color hover:text-primary-background-color h-12 min-w-[120px] shadow-none"
type="button"
>
<div
Expand All @@ -44,7 +44,7 @@ exports[`ThemeBuilder component > renders correctly with given props 1`] = `
</div>
</button>
<button
class="select-none border-2 border-primary px-3 py-2 font-semibold uppercase tracking-tight rounded-md bg-transparent text-primary fill-primary hover:bg-primary hover:fill-primary-background-color hover:text-primary-background-color h-12 min-w-[120px] shadow-none"
class="select-none border-2 border-primary px-3 py-2 font-semibold tracking-tight rounded-md bg-transparent text-primary fill-primary hover:bg-primary hover:fill-primary-background-color hover:text-primary-background-color h-12 min-w-[120px] shadow-none"
type="button"
>
<div
Expand Down
5 changes: 3 additions & 2 deletions src/Components/Tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const Tooltip: FC<ITooltipProps> = ({ text, children, id, place = "top" }) => {
<ReactTooltip
id={id}
place={place}
content={text}
content={text as string}
noArrow
className='border-2 border-primary-text-color/40 !bg-primary-background-color !text-primary-text-color'
opacity={1}
className='border-2 border-primary-text-color/40 !bg-primary-background-color !text-primary-text-color z-50'
/>
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion src/Components/Tooltip/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from "react";

export interface ITooltipProps {
text: string;
text: string | React.ReactNode;
id: string;
children: React.ReactNode;
place?: "top" | "bottom" | "left" | "right";
Expand Down

0 comments on commit ca1a289

Please sign in to comment.