-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Relax Node restriction * Add <manifold-service-card>
- Loading branch information
Showing
7 changed files
with
177 additions
and
4 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
1 change: 1 addition & 0 deletions
1
src/components/manifold-product-card-view/manifold-product-card-view.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
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
127 changes: 127 additions & 0 deletions
127
src/components/manifold-service-card/manifold-service-card.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,127 @@ | ||
// Replaced by <manifold-product-card> (delete this in 1.0) | ||
import { h, Component, Element, State, Prop, Watch } from '@stencil/core'; | ||
|
||
import connection from '../../state/connection'; | ||
import { GraphqlFetch, GraphqlError } from '../../utils/graphqlFetch'; | ||
import logger from '../../utils/logger'; | ||
import loadMark from '../../utils/loadMark'; | ||
|
||
import { ProductCardQuery, ProductCardQueryVariables } from '../../types/graphql'; | ||
|
||
import productCardQuery from '../manifold-product-card/product-card.graphql'; | ||
|
||
// Product has at least one free plan. | ||
const isFree = (product: ProductCardQuery['product']) => | ||
!!(product.plans && product.plans.edges.find(({ node }) => node.free)); | ||
|
||
@Component({ tag: 'manifold-service-card' }) | ||
export class ManifoldServiceCard { | ||
@Element() el: HTMLElement; | ||
/** _(hidden)_ */ | ||
@Prop() graphqlFetch?: GraphqlFetch = connection.graphqlFetch; | ||
@Prop() hideUntilReady?: boolean = false; | ||
@Prop({ reflect: true }) isFeatured?: boolean; | ||
@Prop({ mutable: true }) product?: ProductCardQuery['product']; | ||
@Prop() productLabel?: string; | ||
@Prop() productLinkFormat?: string; | ||
@Prop() preserveEvent?: boolean = false; | ||
@State() free: boolean = false; | ||
@State() errors?: GraphqlError[]; | ||
|
||
@Watch('product') productChange(newProduct: ProductCardQuery['product']) { | ||
if (newProduct) { | ||
this.free = isFree(newProduct); | ||
} | ||
} | ||
|
||
@Watch('productLabel') productLabelChange(newProductLabel: string) { | ||
if (!this.product || (this.product && this.product.label !== newProductLabel)) { | ||
this.fetchProduct(newProductLabel); | ||
} | ||
} | ||
|
||
@loadMark() | ||
componentWillLoad() { | ||
console.warn( | ||
`<manifold-service-card> will be deprecated in version 1.0. Please use <manifold-product-card> instead.` | ||
); | ||
|
||
let call; | ||
|
||
if (this.productLabel) { | ||
call = this.fetchProduct(this.productLabel); | ||
} | ||
|
||
if (this.hideUntilReady) { | ||
return call; | ||
} | ||
return undefined; | ||
} | ||
|
||
get href() { | ||
if (this.productLinkFormat && this.product) { | ||
return this.productLinkFormat.replace(/:product/gi, this.product.label); | ||
} | ||
return ''; // if no format, or product is loading, don’t calculate href | ||
} | ||
|
||
async fetchProduct(productLabel: string) { | ||
if (!this.graphqlFetch || !productLabel) { | ||
return; | ||
} | ||
|
||
const variables: ProductCardQueryVariables = { productLabel }; | ||
const { data, errors } = await this.graphqlFetch<ProductCardQuery>({ | ||
query: productCardQuery, | ||
variables, | ||
element: this.el, | ||
}); | ||
if (data && data.product) { | ||
this.product = data.product; | ||
} | ||
|
||
if (errors) { | ||
this.errors = errors; | ||
} | ||
} | ||
|
||
@logger() | ||
render() { | ||
if (this.product) { | ||
return [ | ||
<manifold-product-card-view | ||
description={this.product.tagline} | ||
isFeatured={this.isFeatured} | ||
isFree={this.free} | ||
logo={this.product.logoUrl} | ||
name={this.product.displayName} | ||
preserveEvent={this.preserveEvent} | ||
productId={this.product.id} | ||
productLabel={this.product.label} | ||
productLinkFormat={this.productLinkFormat} | ||
> | ||
<manifold-forward-slot slot="cta"> | ||
<slot name="cta" /> | ||
</manifold-forward-slot> | ||
</manifold-product-card-view>, | ||
this.errors && | ||
this.errors.map(({ message }) => ( | ||
<manifold-toast alertType="error">{message}</manifold-toast> | ||
)), | ||
]; | ||
} | ||
// ☠ | ||
return ( | ||
<manifold-product-card-view | ||
skeleton={true} | ||
description="Awesome product description" | ||
logo="product.jpg" | ||
name="Awesome product" | ||
> | ||
<manifold-forward-slot slot="cta"> | ||
<slot name="cta" /> | ||
</manifold-forward-slot> | ||
</manifold-product-card-view> | ||
); | ||
} | ||
} |
6992e52
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: