Skip to content

Commit

Permalink
Merge branch 'upkeep/component-post-title' of github.com:10up/block-c…
Browse files Browse the repository at this point in the history
…omponents into upkeep/component-post-title
  • Loading branch information
Sidsector9 committed Apr 1, 2024
2 parents 045956e + f7199b5 commit b5f8cbe
Show file tree
Hide file tree
Showing 5 changed files with 2,033 additions and 180 deletions.
16 changes: 0 additions & 16 deletions components/optional/index.js

This file was deleted.

21 changes: 21 additions & 0 deletions components/optional/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useBlockEditContext } from '@wordpress/block-editor';

interface OptionalProps {
/**
* The value to check for truthiness.
*/
value?: string | number | boolean;

/**
* The children to render if the value is truthy.
*/
children: React.ReactNode;
}

export const Optional: React.FC<OptionalProps> = ({
value = '',
children,
}) => {
const { isSelected } = useBlockEditContext();
return (isSelected || !!value) && children;
};
9 changes: 7 additions & 2 deletions hooks/use-media/index.js → hooks/use-media/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import type { Attachment } from '@wordpress/core-data';

export function useMedia(id) {
export function useMedia(id: number) {
return useSelect(
(select) => {
const { getMedia, isResolving, hasFinishedResolution } = select(coreStore);
Expand All @@ -15,5 +16,9 @@ export function useMedia(id) {
};
},
[id],
);
) as {
media: Attachment | undefined;
isResolvingMedia: boolean;
hasResolvedMedia: boolean;
};
}
Loading

0 comments on commit b5f8cbe

Please sign in to comment.