-
Notifications
You must be signed in to change notification settings - Fork 218
Convert product-elements/price to TypeScript #7683
Changes from all commits
cc2a0c2
e53fb67
ded42d7
4084e25
64684d4
1687c43
609561f
143c111
10fe20e
e6389b6
136e0fb
81dabd5
bfa0594
2bd19b5
8e8b4a0
239e603
31534b5
9e1c763
ae10c57
2f699ca
c6bae5a
0ff8471
4972a43
06d022c
31da04f
864d6ac
451da01
cf3d57e
1ed36b8
42f1a9e
943e0b1
54adbc8
e1d9ac4
c310c8f
fc8bf18
6dd5afb
1092da3
9e101a9
272b7c9
de87d05
f1789ce
6fc405b
48607ed
96e2f1a
b0dc7c3
a27b66d
bc901de
3f8be3f
250b561
7bf8194
a4efbd2
30bd5b3
f8d870b
787d4b8
ba80e47
1e877cc
cf48509
3f87035
99ccf60
bfd2c9e
011f66e
d67011a
2ba1f41
1a3df0d
65cecfa
37884b2
9567d58
fb12f2d
2b86d96
2ea7d66
0cfec28
91e7b12
d068e31
edd5ecf
308d901
989e955
02ec49b
121701a
60fa85d
270f1d6
4fdbda4
66df464
3ce2cb2
9a648ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
AlignmentToolbar, | ||
BlockControls, | ||
useBlockProps, | ||
} from '@wordpress/block-editor'; | ||
import { useEffect } from 'react'; | ||
import type { BlockAlignment } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Block from './block'; | ||
import withProductSelector from '../shared/with-product-selector'; | ||
import { BLOCK_TITLE as label, BLOCK_ICON as icon } from './constants'; | ||
|
||
type UnsupportedAligments = 'wide' | 'full'; | ||
type AllowedAlignments = Exclude< BlockAlignment, UnsupportedAligments >; | ||
|
||
interface BlockAttributes { | ||
textAlign?: AllowedAlignments; | ||
} | ||
|
||
interface Attributes { | ||
textAlign: 'left' | 'center' | 'right'; | ||
} | ||
|
||
interface Context { | ||
queryId: number; | ||
} | ||
|
||
interface Props { | ||
attributes: Attributes; | ||
setAttributes: ( | ||
attributes: Partial< BlockAttributes > & Record< string, unknown > | ||
) => void; | ||
context: Context; | ||
} | ||
|
||
const PriceEdit = ( { | ||
attributes, | ||
setAttributes, | ||
context, | ||
}: Props ): JSX.Element => { | ||
const blockProps = useBlockProps(); | ||
const blockAttrs = { | ||
...attributes, | ||
...context, | ||
}; | ||
const isDescendentOfQueryLoop = Number.isFinite( context.queryId ); | ||
|
||
useEffect( | ||
() => setAttributes( { isDescendentOfQueryLoop } ), | ||
[ setAttributes, isDescendentOfQueryLoop ] | ||
); | ||
|
||
return ( | ||
<> | ||
<BlockControls> | ||
{ isDescendentOfQueryLoop && ( | ||
<AlignmentToolbar | ||
value={ attributes.textAlign } | ||
onChange={ ( textAlign: AllowedAlignments ) => { | ||
setAttributes( { textAlign } ); | ||
} } | ||
/> | ||
) } | ||
</BlockControls> | ||
<div { ...blockProps }> | ||
<Block { ...blockAttrs } /> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default withProductSelector( { icon, label } )( PriceEdit ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { isFeaturePluginBuild } from '@woocommerce/block-settings'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import sharedConfig from '../shared/config'; | ||
|
||
export const supports = { | ||
...sharedConfig.supports, | ||
...( isFeaturePluginBuild() && { | ||
color: { | ||
text: true, | ||
background: false, | ||
link: false, | ||
__experimentalSkipSerialization: true, | ||
}, | ||
typography: { | ||
fontSize: true, | ||
__experimentalFontWeight: true, | ||
__experimentalFontStyle: true, | ||
__experimentalSkipSerialization: true, | ||
}, | ||
__experimentalSelector: '.wc-block-components-product-price', | ||
} ), | ||
}; |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,6 @@ | ||||
export interface BlockAttributes { | ||||
productId?: number; | ||||
className?: string; | ||||
textAlign?: 'left' | 'center' | 'right'; | ||||
isDescendentOfQueryLoop?: boolean; | ||||
Comment on lines
+2
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The attributes are optional to prevent a TS error in the following section:
|
||||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||
export interface BlockAttributes { | ||||
productId: number; | ||||
align: 'left' | 'center' | 'right'; | ||||
productId?: number; | ||||
align?: 'left' | 'center' | 'right'; | ||||
Comment on lines
+2
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part had been changed to prevent a TS error in the following section:
|
||||
isDescendentOfQueryLoop: boolean; | ||||
} |
Uh oh!
There was an error while loading. Please reload this page.