Skip to content

Commit

Permalink
A couple of type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Mar 27, 2024
1 parent a6097ca commit cbe7626
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 14 deletions.
11 changes: 3 additions & 8 deletions packages/element-library/src/product/output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
*/

/**
* External dependencies
* Internal dependencies
*/
import { StoryPropTypes } from '@googleforcreators/elements';
import type { ProductElement } from '../types';

/**
* Returns AMP HTML for saving into post content for displaying in the FE.
*
* @param {Object<*>} props Props.
* @return {*} Rendered component.
* @param props Props.
* @return Rendered component.
*/
function ProductOutput({ element }: { element: ProductElement }) {
const { product } = element;
Expand All @@ -36,8 +35,4 @@ function ProductOutput({ element }: { element: ProductElement }) {
return <amp-story-shopping-tag data-product-id={product.productId} />;
}

ProductOutput.propTypes = {
element: StoryPropTypes.elements.shape.isRequired,
};

export default ProductOutput;
16 changes: 11 additions & 5 deletions packages/element-library/src/shared/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
* External dependencies
*/
import { css } from 'styled-components';
import { generatePatternStyles, Pattern } from '@googleforcreators/patterns';
import {
generatePatternStyles,
type Pattern,
} from '@googleforcreators/patterns';
import { getBorderStyle, getBorderRadius } from '@googleforcreators/masks';
import type { BorderRadius, Element } from '@googleforcreators/elements';

Expand All @@ -44,12 +47,12 @@ export const elementWithPosition = css<Element>`
`;

// TODO: removed round/ceil, calculateFitTextFontSize needs to be improved?
export const elementWithSize = css<{width: number; height: number}>`
export const elementWithSize = css<{ width: number; height: number }>`
width: ${({ width }) => `${width}px`};
height: ${({ height }) => `${height}px`};
`;

export const elementWithRotation = css<{rotationAngle: number}>`
export const elementWithRotation = css<{ rotationAngle: number }>`
transform: ${({ rotationAngle }) => `rotate(${rotationAngle}deg)`};
`;

Expand All @@ -62,7 +65,10 @@ type DataToStyle = (prop: number) => string;
export const elementWithHighlightBorderRadius = ({
borderRadius,
dataToEditorY,
}: { borderRadius: BorderRadius, dataToEditorY?: DataToStyle}) =>
}: {
borderRadius: BorderRadius;
dataToEditorY?: DataToStyle;
}) =>
dataToEditorY &&
css`
border-radius: ${dataToEditorY(borderRadius?.topLeft || 0)}px
Expand Down Expand Up @@ -107,7 +113,7 @@ export const elementWithTextParagraphStyle = css<{
margin: number;
padding?: number;
lineHeight: number;
textAlign: 'left'|'right'|'center'|'justify'|'initial'|'inherit';
textAlign: 'left' | 'right' | 'center' | 'justify' | 'initial' | 'inherit';
}>`
margin: ${({ margin }) => margin};
padding: ${({ padding }) => padding || 0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '@googleforcreators/patterns';
import { useTransformHandler } from '@googleforcreators/transform';
import type { ElementId } from '@googleforcreators/elements';
import type { RefObject } from "react";
import type { RefObject } from 'react';

function useColorTransformHandler({
id,
Expand Down
29 changes: 29 additions & 0 deletions packages/element-library/src/typings/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

interface AmpStoryShoppingTag {
'data-product-id'?: string | number;
}

declare global {
namespace JSX {
interface IntrinsicElements {
'amp-story-shopping-tag': AmpStoryShoppingTag;
}
}
}

export {};
23 changes: 23 additions & 0 deletions packages/element-library/src/typings/svg.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare module '*.svg' {
import type { FunctionComponent, SVGProps } from 'react';
const ReactComponent: FunctionComponent<
SVGProps<SVGElement> & { title?: string }
>;
export default ReactComponent;
}

0 comments on commit cbe7626

Please sign in to comment.