|
1 |
| -import { FeaturesSelect, Label, Title } from '@newfold/ui-component-library'; |
2 |
| -import { UserIcon as UserIconOutline, BuildingOfficeIcon as BuildingOfficeIconOutline, ShoppingBagIcon as ShoppingBagIconOutline } from '@heroicons/react/24/outline'; |
3 |
| -import { UserIcon as UserIconSolid, BuildingOfficeIcon as BuildingOfficeIconSolid, ShoppingBagIcon as ShoppingBagIconSolid } from '@heroicons/react/24/solid'; |
| 1 | +import { SelectField } from '@newfold/ui-component-library'; |
| 2 | +import classNames from 'classnames'; |
4 | 3 |
|
5 | 4 | const SiteTypeSelector = ( { value: selectedSiteType, onChange } ) => {
|
6 | 5 | const siteTypeOptions = [
|
7 | 6 | {
|
8 |
| - id: 'nfd-onboarding-site-type-option__blog', |
9 |
| - name: 'nfd-onboarding-site-type-option-group', |
10 | 7 | value: 'personal',
|
11 | 8 | label: __( 'Personal', 'wp-module-onboarding' ),
|
12 |
| - description: __( 'Share your story, thoughts, and ideas.', 'wp-module-onboarding' ), |
13 |
| - Icon: UserIconOutline, |
14 |
| - IconSelected: UserIconSolid, |
15 | 9 | },
|
16 | 10 | {
|
17 |
| - id: 'nfd-onboarding-site-type-option__business-service', |
18 |
| - name: 'nfd-onboarding-site-type-option-group', |
19 | 11 | value: 'business',
|
20 | 12 | label: __( 'Business & Service', 'wp-module-onboarding' ),
|
21 |
| - description: __( 'Showcase your work and services.', 'wp-module-onboarding' ), |
22 |
| - Icon: BuildingOfficeIconOutline, |
23 |
| - IconSelected: BuildingOfficeIconSolid, |
24 | 13 | },
|
25 | 14 | {
|
26 |
| - id: 'nfd-onboarding-site-type-option__ecommerce', |
27 |
| - name: 'nfd-onboarding-site-type-option-group', |
28 | 15 | value: 'ecommerce',
|
29 | 16 | label: __( 'Online Store', 'wp-module-onboarding' ),
|
30 |
| - description: __( 'Sell your products and services online.', 'wp-module-onboarding' ), |
31 |
| - Icon: ShoppingBagIconOutline, |
32 |
| - IconSelected: ShoppingBagIconSolid, |
33 | 17 | },
|
34 | 18 | ];
|
35 | 19 |
|
36 |
| - const handleChange = ( event ) => { |
37 |
| - const newValue = event.target.value; |
| 20 | + const getSelectedLabel = ( value ) => { |
| 21 | + const option = siteTypeOptions.find( ( o ) => o.value === value ); |
| 22 | + return option ? option.label : __( 'Site Type', 'wp-module-onboarding' ); |
| 23 | + }; |
| 24 | + |
| 25 | + const handleChange = ( newValue ) => { |
38 | 26 | // Validate the value is one of the options.
|
39 | 27 | const allowedValues = siteTypeOptions.map( ( option ) => option.value );
|
40 | 28 | if ( allowedValues.includes( newValue ) && newValue !== selectedSiteType ) {
|
41 | 29 | onChange( newValue );
|
42 | 30 | }
|
43 | 31 | };
|
44 | 32 |
|
45 |
| - /** |
46 |
| - * Styles for parts that are not exposed by the FeaturesSelect component. |
47 |
| - */ |
48 |
| - const getCustomStyles = () => { |
49 |
| - return ( |
50 |
| - <style> |
51 |
| - { ` |
52 |
| - .nfd-onboarding-site-type-options .nfd-features-select__feature .nfd-label { |
53 |
| - box-shadow: 0px 4px 9.6px 10px #85BCF209 !important; |
54 |
| - } |
55 |
| -
|
56 |
| - .nfd-onboarding-site-type-options .nfd-features-select__feature-content { |
57 |
| - padding: 1rem !important; |
58 |
| - border-color: #DEE3E9 !important; |
59 |
| - width: 100% !important; |
60 |
| - } |
61 |
| -
|
62 |
| - .nfd-onboarding-site-type-options .nfd-features-select__feature .nfd-features-select__feature-input:checked + .nfd-label .nfd-features-select__feature-content { |
63 |
| - background-color: #EAF4FB !important; |
64 |
| - } |
65 |
| - ` } |
66 |
| - </style> |
67 |
| - ); |
68 |
| - }; |
69 |
| - |
70 |
| - const SiteTypeOption = ( { option } ) => { |
71 |
| - const Icon = option.Icon; |
72 |
| - const IconSelected = option.IconSelected; |
73 |
| - |
74 |
| - return ( |
75 |
| - <FeaturesSelect.Feature |
76 |
| - key={ option.id } |
77 |
| - id={ option.id } |
78 |
| - name={ option.name } |
79 |
| - value={ option.value } |
80 |
| - checked={ selectedSiteType === option.value } |
81 |
| - screenReaderLabel={ option.label } |
82 |
| - onChange={ handleChange } |
83 |
| - className="nfd-w-[30%] nfd-flex-grow [&>label]:nfd-h-full [&>label]:nfd-flex mobile:nfd-w-full" |
84 |
| - > |
85 |
| - <div className="nfd-flex nfd-flex-col nfd-self-stretch nfd-gap-1 nfd-text-left"> |
86 |
| - { selectedSiteType === option.value ? <IconSelected className="nfd-h-6 nfd-w-6 nfd-text-primary nfd-mb-1" /> : <Icon className="nfd-h-6 nfd-w-6 nfd-text-primary nfd-mb-1" /> } |
87 |
| - <Title as="h4" className="nfd-text-sm nfd-font-semibold">{ option.label }</Title> |
88 |
| - <p className="nfd-text-sm">{ option.description }</p> |
89 |
| - </div> |
90 |
| - </FeaturesSelect.Feature> |
91 |
| - ); |
92 |
| - }; |
93 |
| - |
94 | 33 | return (
|
95 |
| - <div className="nfd-onboarding-site-type-options nfd-pb-7 nfd-border-b"> |
96 |
| - { getCustomStyles() } |
97 |
| - <Label |
| 34 | + <div className="nfd-onboarding-site-type-options nfd-w-1/2 mobile:nfd-w-full"> |
| 35 | + <SelectField |
98 | 36 | label={ __( 'Site Type', 'wp-module-onboarding' ) }
|
99 |
| - required={ true } |
100 |
| - requiredIndicator={ true } |
101 |
| - className="nfd-mb-2 nfd-block" |
| 37 | + labelProps={ { |
| 38 | + required: true, |
| 39 | + requiredIndicator: true, |
| 40 | + } } |
| 41 | + options={ siteTypeOptions } |
| 42 | + onChange={ handleChange } |
| 43 | + value={ selectedSiteType || '' } |
| 44 | + selectedLabel={ getSelectedLabel( selectedSiteType ) } |
| 45 | + className={ classNames( |
| 46 | + ! selectedSiteType && '[&_button>span]:nfd-text-gray-500', |
| 47 | + ) } |
102 | 48 | />
|
103 |
| - <FeaturesSelect |
104 |
| - behavior="radio" |
105 |
| - className="nfd-flex mobile:nfd-flex-col" |
106 |
| - > |
107 |
| - { siteTypeOptions.map( ( option ) => <SiteTypeOption key={ option.id } option={ option } /> ) } |
108 |
| - </FeaturesSelect> |
109 | 49 | </div>
|
110 | 50 | );
|
111 | 51 | };
|
|
0 commit comments