Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): add image component
- Loading branch information
Showing
16 changed files
with
203 additions
and
28 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { createApp } from "vue"; | ||
import router from "./router"; | ||
import App from "./App.vue"; | ||
import prismic from "./prismic"; | ||
|
||
createApp(App).use(prismic).mount("#app"); | ||
createApp(App).use(router).use(prismic).mount("#app"); |
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,25 @@ | ||
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router"; | ||
|
||
const routes: Array<RouteRecordRaw> = [ | ||
{ | ||
path: "/", | ||
name: "Index", | ||
component: () => | ||
import(/* webpackChunkName: "index" */ "../views/index.vue") | ||
}, | ||
{ | ||
path: "/components/image", | ||
name: "ComponentsImage", | ||
component: () => | ||
import( | ||
/* webpackChunkName: "components--image" */ "../views/components/image.vue" | ||
) | ||
} | ||
]; | ||
|
||
const router = createRouter({ | ||
history: createWebHistory(), | ||
routes | ||
}); | ||
|
||
export default router; |
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,38 @@ | ||
<template> | ||
<div class="componentsImage"> | ||
<prismic-image :field="simple" /> | ||
<prismic-image :field="simple.twitter_variant" /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from "vue"; | ||
export default defineComponent({ | ||
name: "ComponentsImage", | ||
data() { | ||
return { | ||
simple: { | ||
dimensions: { | ||
width: 1200, | ||
height: 600 | ||
}, | ||
alt: "Atlantic Puffin Flying", | ||
copyright: "Unsplash", | ||
url: | ||
"https://images.prismic.io/200629-sms-hoy/7d997f6a-0ab0-475d-a1a3-d1c1056d6f39_ray-hennessy-PHnBeYvpWgA-unsplash.jpg?auto=compress,format&rect=0,198,2400,1200&w=1200&h=600", | ||
twitter_variant: { | ||
dimensions: { | ||
width: 600, | ||
height: 600 | ||
}, | ||
alt: "Atlantic Puffin Flying", | ||
copyright: "Unsplash", | ||
url: | ||
"https://images.prismic.io/200629-sms-hoy/7d997f6a-0ab0-475d-a1a3-d1c1056d6f39_ray-hennessy-PHnBeYvpWgA-unsplash.jpg?auto=compress,format&rect=0,198,2400,1200&w=600&h=600" | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
</script> |
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,11 @@ | ||
<template> | ||
<div class="index">index</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from "vue"; | ||
export default defineComponent({ | ||
name: "Index" | ||
}); | ||
</script> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { defineComponent, h, PropType } from "vue"; | ||
|
||
interface ImageField { | ||
url: string; | ||
alt?: string; | ||
copyright?: string; | ||
} | ||
|
||
export const PrismicImage = defineComponent({ | ||
name: "PrismicImage", | ||
props: { | ||
field: { | ||
type: Object as PropType<ImageField>, | ||
required: true | ||
} | ||
}, | ||
render() { | ||
const { url: src, alt, copyright } = this.field; | ||
|
||
return h("img", { src, alt, copyright }); | ||
} | ||
}); |
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 @@ | ||
export * from "./Image"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { App } from "vue"; | ||
import type { PrismicPluginOptions } from "../types"; | ||
import { PrismicImage } from "../components"; | ||
import { SDK, SDKWithInterface } from "./SDK"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ComponentsInterface {} | ||
|
||
export class Components | ||
extends SDK | ||
implements SDKWithInterface<ComponentsInterface> { | ||
constructor(options: Required<PrismicPluginOptions>) { | ||
super(options); | ||
} | ||
|
||
get interface(): ComponentsInterface { | ||
return {}; | ||
} | ||
|
||
install(app: App): void { | ||
app.component(PrismicImage.name, PrismicImage); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { App } from "vue"; | ||
import type { PrismicPluginOptions } from "../types"; | ||
|
||
export interface SDKWithInterface< | ||
Interface extends Record<string, unknown> | unknown = Record<string, never> | ||
> { | ||
options: Required<PrismicPluginOptions>; | ||
interface: Interface; | ||
install: (app: App) => void; | ||
} | ||
|
||
export type SDKWithInterfaceKeys = keyof SDKWithInterface; | ||
|
||
export abstract class SDK implements SDKWithInterface<unknown> { | ||
constructor(public options: Required<PrismicPluginOptions>) {} | ||
|
||
abstract get interface(): unknown; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars | ||
install(app: App): void {} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export * from "./SDK"; | ||
|
||
export * from "./DOM"; | ||
export * from "./Client"; | ||
export * from "./Components"; |
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