Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4998 from ampproject/feature/4704-settings-screen…
…-updates Incorporate wizard components onto Settings screen
- Loading branch information
Showing
152 changed files
with
3,136 additions
and
1,825 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { ToggleControl } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.css'; | ||
|
||
/** | ||
* Styled toggle control. | ||
* | ||
* @param {Object} props Component props. | ||
* @param {boolean} props.checked Whether the toggle is on. | ||
* @param {boolean} props.disabled Whether the toggle is disabled. | ||
* @param {Function} props.onChange Change handler. | ||
* @param {?string} props.text Toggle text. | ||
* @param {string} props.title Toggle title. | ||
*/ | ||
export function AMPSettingToggle( { checked, disabled = false, onChange, text, title } ) { | ||
return ( | ||
<div className={ `amp-setting-toggle ${ disabled ? 'amp-setting-toggle--disabled' : '' }` }> | ||
<ToggleControl | ||
checked={ ! disabled && checked } | ||
label={ ( | ||
<div className="amp-setting-toggle__label-text"> | ||
<h3> | ||
{ title } | ||
</h3> | ||
{ text && ( | ||
<p> | ||
{ text } | ||
</p> ) } | ||
</div> | ||
) } | ||
onChange={ onChange } | ||
/> | ||
</div> | ||
); | ||
} | ||
AMPSettingToggle.propTypes = { | ||
checked: PropTypes.bool.isRequired, | ||
disabled: PropTypes.bool, | ||
onChange: PropTypes.func.isRequired, | ||
text: PropTypes.string, | ||
title: PropTypes.string.isRequired, | ||
}; |
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,49 @@ | ||
/** | ||
* AMP setting toggle component. | ||
*/ | ||
.amp-setting-toggle__label-text h3 { | ||
font-weight: 700; | ||
font-size: 1.25rem; | ||
margin-bottom: 1rem; | ||
margin-top: 0; | ||
} | ||
|
||
.amp-setting-toggle__label-text p:last-child { | ||
margin-bottom: 0; | ||
} | ||
|
||
.amp-setting-toggle .components-toggle-control .components-base-control__field .components-toggle-control__label { | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.amp-setting-toggle__illustration { | ||
padding-bottom: 1.5rem; | ||
|
||
@media screen and (min-width: 783px) { | ||
padding: 0 1.5rem; | ||
} | ||
} | ||
|
||
.amp .amp-setting-toggle .components-form-toggle { | ||
margin-bottom: 2.25rem; | ||
margin-right: 2.25rem; | ||
} | ||
|
||
.amp-setting-toggle .components-toggle-control .components-base-control__field { | ||
align-items: baseline; | ||
margin-bottom: 0; | ||
} | ||
|
||
.amp-setting-toggle .components-form-toggle.is-checked .components-form-toggle__track { | ||
background-color: var(--brand); | ||
} | ||
|
||
.amp-setting-toggle .components-form-toggle__input:focus + .components-form-toggle__track { | ||
box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--brand); | ||
} | ||
|
||
.amp-setting-toggle--disabled .components-form-toggle { | ||
pointer-events: none; | ||
opacity: 0.5; | ||
} |
120 changes: 120 additions & 0 deletions
120
assets/src/components/amp-setting-toggle/test/__snapshots__/index.js.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,69 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { act } from 'react-dom/test-utils'; | ||
import { create } from 'react-test-renderer'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { render } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { AMPSettingToggle } from '../'; | ||
|
||
let container; | ||
|
||
describe( 'AMPSettingToggle', () => { | ||
beforeEach( () => { | ||
container = document.createElement( 'div' ); | ||
document.body.appendChild( container ); | ||
} ); | ||
|
||
afterEach( () => { | ||
document.body.removeChild( container ); | ||
container = null; | ||
} ); | ||
|
||
it( 'matches snapshots', () => { | ||
let wrapper = create( | ||
<AMPSettingToggle checked={ true } onChange={ () => null } text={ 'My text' } title={ 'My title' } />, | ||
); | ||
expect( wrapper.toJSON() ).toMatchSnapshot(); | ||
|
||
wrapper = create( | ||
<AMPSettingToggle checked={ false } onChange={ () => null } title={ 'My title' } />, | ||
); | ||
expect( wrapper.toJSON() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'has correct elements and text', () => { | ||
act( () => { | ||
render( | ||
<AMPSettingToggle title="My title" onChange={ () => null } checked={ false }> | ||
{ 'children' } | ||
</AMPSettingToggle>, | ||
container, | ||
); | ||
} ); | ||
|
||
expect( container.querySelector( 'h3' ).textContent ).toBe( 'My title' ); | ||
expect( container.querySelector( 'p' ) ).toBeNull(); | ||
expect( container.querySelector( 'input:checked' ) ).toBeNull(); | ||
|
||
act( () => { | ||
render( | ||
<AMPSettingToggle title="My title" onChange={ () => null } checked={ true } text="My text"> | ||
{ 'children' } | ||
</AMPSettingToggle>, | ||
container, | ||
); | ||
} ); | ||
|
||
expect( container.querySelector( 'h3' ).textContent ).toBe( 'My title' ); | ||
expect( container.querySelector( 'p' ).textContent ).toBe( 'My text' ); | ||
expect( container.querySelector( 'input:checked' ) ).not.toBeNull(); | ||
} ); | ||
} ); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.