Skip to content

Commit cd92eeb

Browse files
authored
Fix starscape when plugin isn't active (#341)
1 parent 0f5a7d7 commit cd92eeb

File tree

7 files changed

+413
-2
lines changed

7 files changed

+413
-2
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import v1 from './v1';
2+
import v2 from './v2';
23

34
// Deprecations should run in reverse chronological order. Most probable
45
// deprecations to run are the most recent. This ordering makes the process
56
// a little more performant.
6-
export default [ v1 ];
7+
export default [ v2, v1 ];
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
export default {
2+
align: {
3+
type: 'string',
4+
default: 'full',
5+
},
6+
color: {
7+
type: 'string',
8+
default: '#fff',
9+
},
10+
background: {
11+
type: 'string',
12+
// Default #000 in style.scss.
13+
},
14+
intensity: {
15+
type: 'number',
16+
default: 80,
17+
},
18+
density: {
19+
type: 'number',
20+
default: 20,
21+
},
22+
speed: {
23+
type: 'number',
24+
default: 20,
25+
},
26+
areaWidth: {
27+
type: 'integer',
28+
default: 1920,
29+
},
30+
areaHeight: {
31+
type: 'integer',
32+
default: 1080,
33+
},
34+
minHeight: {
35+
type: 'string',
36+
// Default 430px in style.scss.
37+
},
38+
layout: {
39+
type: 'object',
40+
default: {
41+
type: 'constrained',
42+
},
43+
},
44+
tagName: {
45+
type: 'string',
46+
default: 'div',
47+
},
48+
templateLock: {
49+
type: [ 'string', 'boolean' ],
50+
enum: [ 'all', 'insert', 'contentOnly', false ],
51+
},
52+
allowedBlocks: {
53+
type: 'array',
54+
},
55+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { __ } from '@wordpress/i18n';
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import attributes from './attributes';
10+
import save from './save';
11+
12+
export default {
13+
supports: {
14+
className: true,
15+
align: [ 'wide', 'full' ],
16+
color: {
17+
heading: true,
18+
text: true,
19+
link: true,
20+
background: false,
21+
gradients: false,
22+
},
23+
html: false,
24+
layout: {
25+
allowJustification: false,
26+
},
27+
spacing: {
28+
padding: true,
29+
margin: [ 'top', 'bottom' ],
30+
blockGap: true,
31+
__experimentalDefaultControls: {
32+
padding: true,
33+
blockGap: true,
34+
},
35+
},
36+
},
37+
attributes,
38+
save,
39+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import Starscape from './starscape';
10+
import { genStars, genAnimations } from './utils';
11+
12+
function StarscapeSave( { attributes } ) {
13+
const {
14+
background,
15+
color,
16+
intensity,
17+
density,
18+
speed,
19+
minHeight,
20+
areaWidth,
21+
areaHeight,
22+
tagName,
23+
} = attributes;
24+
25+
const starStyles = genStars( { color, density, areaWidth, areaHeight } );
26+
const animationStyles = genAnimations( { speed } );
27+
28+
const blockProps = useBlockProps.save( {
29+
style: { background, minHeight },
30+
} );
31+
32+
const innerBlocksProps = useInnerBlocksProps.save( {
33+
className: 'wp-block-a8c-starscape__inner',
34+
} );
35+
36+
return (
37+
<Starscape
38+
as={ tagName }
39+
starStyles={ starStyles }
40+
animationStyles={ animationStyles }
41+
intensity={ intensity }
42+
{ ...blockProps }
43+
>
44+
<div { ...innerBlocksProps } />
45+
</Starscape>
46+
);
47+
}
48+
49+
export default StarscapeSave;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { forwardRef } from '@wordpress/element';
5+
6+
/**
7+
* @typedef {Object} StarscapeProps
8+
* @property {string} [as] HTML tag name.
9+
* @property {Object} starStyles Styles for the stars.
10+
* @property {Object} animationStyles Styles for the animation.
11+
* @property {number} intensity Intensity of the stars.
12+
* @property {WPElement} [children] Children of the component.
13+
*/
14+
15+
/**
16+
* Starscape background effect component.
17+
*
18+
* @param {StarscapeProps} props Starscape props
19+
* @param {Ref} ref React ref
20+
*
21+
* @returns {WPElement} Starscape component
22+
*/
23+
const Starscape = (
24+
{
25+
as: Component = 'div',
26+
starStyles,
27+
animationStyles,
28+
intensity,
29+
children,
30+
...props
31+
},
32+
ref
33+
) => {
34+
return (
35+
<Component ref={ ref } { ...props }>
36+
{ [ 0, 1, 2 ].map( ( i ) => (
37+
<div
38+
key={ i }
39+
className="wp-block-a8c-starscape__stars"
40+
style={ {
41+
opacity: intensity / 100,
42+
...starStyles[ i ],
43+
...animationStyles[ i ],
44+
} }
45+
/>
46+
) ) }
47+
{ children }
48+
</Component>
49+
);
50+
};
51+
52+
export default forwardRef( Starscape );

0 commit comments

Comments
 (0)