-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
138 additions
and
174 deletions.
There are no files selected for viewing
20 changes: 0 additions & 20 deletions
20
src/OnboardingSPA/components/RadioControl/RadioControlSkeleton/index.js
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
src/OnboardingSPA/components/RadioControl/RadioControlState/index.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
src/OnboardingSPA/components/RadioControlWithSkeleton/index.js
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,68 @@ | ||
import { __ } from '@wordpress/i18n'; | ||
import { RadioControl } from '@wordpress/components'; | ||
import { useState, useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Renders Skeletons for Radio Control. | ||
* | ||
* @property {number} data The options to be renedered | ||
* @property {number} watch The variable to be awaited for | ||
* @property {string} callback The Render function in parent to be called | ||
* @property {string} className The class name for the Live Preview | ||
* | ||
*/ | ||
const RadioControlWithSkeleton = ({ | ||
data, | ||
watch, | ||
selected, | ||
callback, | ||
className, | ||
}) => { | ||
|
||
const [rerender, doRerender] = useState(0); | ||
|
||
useEffect(() => doRerender(1), [watch, selected]); | ||
|
||
const buildDummyPreviews = () => { | ||
var customItems = []; | ||
|
||
for (let idx = 0; idx < data.length; idx++) | ||
customItems.push(<div className="radio-control-skeleton-item" />); | ||
|
||
return ( | ||
<div className='radio-control-skeleton'> | ||
{customItems} | ||
</div> | ||
); | ||
}; | ||
|
||
const buildRealPreview = () => { | ||
return ( | ||
<RadioControl | ||
className={`${className} radio-control-main`} | ||
selected={selected} | ||
options={data.map((option) => { | ||
return { | ||
label: __( | ||
option.content, | ||
'wp-module-onboarding' | ||
), | ||
value: __( | ||
option.value, | ||
'wp-module-onboarding' | ||
), | ||
}; | ||
})} | ||
onChange={(value) => callback(value)} | ||
/> | ||
); | ||
}; | ||
|
||
return !watch ? buildDummyPreviews() : | ||
<> | ||
{watch ? <div style={{ display: 'none' }}>{rerender}</div> : null} | ||
{buildRealPreview()} | ||
</>; | ||
}; | ||
|
||
export default RadioControlWithSkeleton; |
File renamed without changes.
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