File tree Expand file tree Collapse file tree 6 files changed +43
-34
lines changed
src/Components/AddSocialPlatform Expand file tree Collapse file tree 6 files changed +43
-34
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @programmer_network/yail" ,
3- "version" : " 1.0.189 " ,
3+ "version" : " 1.0.190 " ,
44 "description" : " Programmer Network's official UI library for React" ,
55 "author" : " Aleksandar Grbic - (https://programmer.network)" ,
66 "publishConfig" : {
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ export default {
99} ;
1010
1111const SOCIAL_PLATFORMS = [
12+ {
13+ name : "Website" ,
14+ url : ""
15+ } ,
1216 {
1317 name : "Github" ,
1418 url : "github.com/"
@@ -73,11 +77,6 @@ export const Default = () => {
7377 < AddSocialPlatform
7478 platforms = { SOCIAL_PLATFORMS }
7579 onAdd = { data => console . log ( data ) }
76- valueProps = { {
77- name : "cool" ,
78- label : "Story" ,
79- hint : "Username, a slug or a handle. Different platforms call it differently. Do not include the base URL."
80- } }
8180 />
8281 </ div >
8382 ) ;
Original file line number Diff line number Diff line change 1+ export const schema = {
2+ type : "object" ,
3+ properties : {
4+ platform : {
5+ type : "string" ,
6+ minLength : 1 ,
7+ errorMessage : "Please select a platform"
8+ } ,
9+ url : {
10+ type : "string" ,
11+ minLength : 1 ,
12+ errorMessage : "Please enter a username"
13+ }
14+ } ,
15+ required : [ "platform" , "url" ]
16+ } ;
Original file line number Diff line number Diff line change @@ -4,38 +4,20 @@ import { FC } from "react";
44import Button from "Components/Button" ;
55import { Input , Select } from "Components/Inputs" ;
66
7+ import { schema } from "./constant" ;
78import { IAddSocialPlatformProps } from "./types" ;
9+ import { getValueHint , getValueLabel } from "./utils" ;
810
911const AddSocialPlatform : FC < IAddSocialPlatformProps > = ( {
1012 onAdd,
11- platforms,
12- valueProps = {
13- name : "" ,
14- label : "" ,
15- hint : ""
16- }
13+ platforms
1714} ) => {
1815 const form = useAJVForm (
1916 {
2017 platform : "" ,
2118 url : ""
2219 } ,
23- {
24- type : "object" ,
25- properties : {
26- platform : {
27- type : "string" ,
28- minLength : 1 ,
29- errorMessage : "Please select a platform"
30- } ,
31- url : {
32- type : "string" ,
33- minLength : 1 ,
34- errorMessage : "Please enter a username"
35- }
36- } ,
37- required : [ "platform" , "url" ]
38- }
20+ schema
3921 ) ;
4022
4123 return (
@@ -54,7 +36,9 @@ const AddSocialPlatform: FC<IAddSocialPlatformProps> = ({
5436 />
5537 < div className = 'yl-col-span-5' >
5638 < Input
57- { ...valueProps }
39+ name = 'url'
40+ label = { getValueLabel ( form . state . platform . value ) }
41+ hint = { getValueHint ( form . state . platform . value ) }
5842 value = { form . state . url . value }
5943 error = { form . state . url . error }
6044 onChange = { form . set }
Original file line number Diff line number Diff line change 11export interface IAddSocialPlatformProps {
22 platforms : { name : string ; url : string } [ ] ;
33 onAdd : ( data : Record < string , string > ) => void ;
4- valueProps ?: {
5- name : string ;
6- label : string ;
7- hint ?: string ;
8- } ;
94}
Original file line number Diff line number Diff line change 1+ export const getValueHint = ( platform : string ) : string => {
2+ if ( platform === "Website" ) {
3+ return "The URL of your website. Include the protocol (http:// or https://)." ;
4+ }
5+
6+ return "Username, a slug or a handle. Different platforms call it differently. Do not include the base URL." ;
7+ } ;
8+
9+ export const getValueLabel = ( platform : string ) : string => {
10+ if ( platform === "Website" ) {
11+ return "URL" ;
12+ }
13+
14+ return "Username" ;
15+ } ;
You can’t perform that action at this time.
0 commit comments