-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
InputControl: Add padding wrapper for prefix/suffix (#42378)
* InputControl: Add padding wrapper for prefix/suffix * Add changelog * Update snapshot * Memoize and simplify context value * Remove padding props * Rename wrapper component * Rename files * Fixup changelog * Fixup
- Loading branch information
Showing
10 changed files
with
202 additions
and
26 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
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
48 changes: 48 additions & 0 deletions
48
packages/components/src/input-control/input-prefix-wrapper.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,48 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ForwardedRef } from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { Spacer } from '../spacer'; | ||
import { | ||
WordPressComponentProps, | ||
contextConnect, | ||
useContextSystem, | ||
} from '../ui/context'; | ||
import type { InputControlPrefixWrapperProps } from './types'; | ||
|
||
function UnconnectedInputControlPrefixWrapper( | ||
props: WordPressComponentProps< InputControlPrefixWrapperProps, 'div' >, | ||
forwardedRef: ForwardedRef< any > | ||
) { | ||
const derivedProps = useContextSystem( props, 'InputControlPrefixWrapper' ); | ||
|
||
return ( | ||
<Spacer marginBottom={ 0 } { ...derivedProps } ref={ forwardedRef } /> | ||
); | ||
} | ||
|
||
/** | ||
* A convenience wrapper for the `prefix` when you want to apply | ||
* standard padding in accordance with the size variant. | ||
* | ||
* ```jsx | ||
* import { | ||
* __experimentalInputControl as InputControl, | ||
* __experimentalInputControlPrefixWrapper as InputControlPrefixWrapper, | ||
* } from '@wordpress/components'; | ||
* | ||
* <InputControl | ||
* prefix={<InputControlPrefixWrapper>@</InputControlPrefixWrapper>} | ||
* /> | ||
* ``` | ||
*/ | ||
export const InputControlPrefixWrapper = contextConnect( | ||
UnconnectedInputControlPrefixWrapper, | ||
'InputControlPrefixWrapper' | ||
); | ||
|
||
export default InputControlPrefixWrapper; |
48 changes: 48 additions & 0 deletions
48
packages/components/src/input-control/input-suffix-wrapper.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,48 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ForwardedRef } from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { Spacer } from '../spacer'; | ||
import { | ||
WordPressComponentProps, | ||
contextConnect, | ||
useContextSystem, | ||
} from '../ui/context'; | ||
import type { InputControlSuffixWrapperProps } from './types'; | ||
|
||
function UnconnectedInputControlSuffixWrapper( | ||
props: WordPressComponentProps< InputControlSuffixWrapperProps, 'div' >, | ||
forwardedRef: ForwardedRef< any > | ||
) { | ||
const derivedProps = useContextSystem( props, 'InputControlSuffixWrapper' ); | ||
|
||
return ( | ||
<Spacer marginBottom={ 0 } { ...derivedProps } ref={ forwardedRef } /> | ||
); | ||
} | ||
|
||
/** | ||
* A convenience wrapper for the `suffix` when you want to apply | ||
* standard padding in accordance with the size variant. | ||
* | ||
* ```jsx | ||
* import { | ||
* __experimentalInputControl as InputControl, | ||
* __experimentalInputControlSuffixWrapper as InputControlSuffixWrapper, | ||
* } from '@wordpress/components'; | ||
* | ||
* <InputControl | ||
* suffix={<InputControlSuffixWrapper>%</InputControlSuffixWrapper>} | ||
* /> | ||
* ``` | ||
*/ | ||
export const InputControlSuffixWrapper = contextConnect( | ||
UnconnectedInputControlSuffixWrapper, | ||
'InputControlSuffixWrapper' | ||
); | ||
|
||
export default InputControlSuffixWrapper; |
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