-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust input styling, AddSocialPlatform Component
- Loading branch information
Showing
15 changed files
with
193 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/Components/AddSocialPlatform/AddSocialPlatform.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters