Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit c86d0e6

Browse files
Merge pull request #214 from TylerAPfledderer/feat/create-c-image
feat(c-image): create image components
2 parents 1cb3773 + 40eb091 commit c86d0e6

21 files changed

+633
-1
lines changed

packages/c-image/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# @chakra-ui/c-image
2+
3+
Image
4+
5+
## Installation
6+
7+
```sh
8+
yarn add @chakra-ui/c-image
9+
# or
10+
npm i @chakra-ui/c-image
11+
```

packages/c-image/examples/basic.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<c-image
3+
:width="['100px', '200px']"
4+
src="http://example.com/non-existent-image.jpg"
5+
alt="welcome"
6+
:onLoad="basicLoad"
7+
:onError="basicError"
8+
/>
9+
</template>
10+
<script setup lang="ts">
11+
import { CImage } from "../index"
12+
13+
const props = {}
14+
15+
const basicLoad = () => console.log("Loaded basic image")
16+
17+
const basicError = () => console.error("Whoops! It's broken")
18+
</script>

packages/c-image/examples/bug.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<div>
3+
<c-image :src="src" />
4+
<button :style="{ background: 'revert', padding: 'revert' }" @click="click">
5+
set image
6+
</button>
7+
<p>src set to Avatar: {{ src }}</p>
8+
</div>
9+
</template>
10+
<script setup lang="ts">
11+
import { ref } from "vue"
12+
import { CImage } from "../src"
13+
14+
const src = ref("")
15+
16+
const click = () =>
17+
(src.value =
18+
"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png")
19+
</script>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<template>
2+
<c-image src="https://loremflickr.com/240/240">
3+
<div :style="{ width: '240px', height: '240px', background: 'red' }" />
4+
</c-image>
5+
</template>
6+
<script setup lang="ts">
7+
import { CImage } from "../index"
8+
</script>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<c-image
3+
src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
4+
w="{240}"
5+
h="{240}"
6+
fallbackStrategy="onError"
7+
fallbackSrc="https://via.placeholder.com/240"
8+
/>
9+
<c-image
10+
w="{240}"
11+
h="{240}"
12+
src="https://bit.ly/dan-abramov"
13+
fallbackStrategy="beforeLoadOrError"
14+
fallbackSrc="https://via.placeholder.com/240"
15+
/>
16+
</template>
17+
<script setup lang="ts">
18+
import { CImage } from "../index"
19+
</script>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<c-image
3+
src="https://loremflickr.com/240/240"
4+
fallbackSrc="https://via.placeholder.com/240"
5+
/>
6+
</template>
7+
<script setup lang="ts">
8+
import { CImage } from "../index"
9+
</script>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<c-image
3+
src="https://loremflickr.com/240/240"
4+
fallbackSrc="https://via.placeholder.com/240"
5+
fit="cover"
6+
htmlWidth="400px"
7+
htmlHeight="300px"
8+
/>
9+
</template>
10+
<script setup lang="ts">
11+
import { CImage } from "../index"
12+
</script>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<c-image
3+
src="https://loremflickr.com/240/240"
4+
fallbackSrc="https://via.placeholder.com/240"
5+
htmlWidth="300"
6+
htmlHeight="300"
7+
@load="load"
8+
/>
9+
</template>
10+
<script setup lang="ts">
11+
import { CImage } from "../index"
12+
13+
const load = () => {
14+
console.log("loaded")
15+
}
16+
</script>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<template>
2+
<c-image
3+
ref="firstRef"
4+
srcSet="//fake.image/ 1x"
5+
:onLoad="firstLog"
6+
:onError="firstLog"
7+
/>
8+
<c-img
9+
ref="secondRef"
10+
srcSet="//lorempixel.com/100/100/ 1x"
11+
:onLoad="secondLog"
12+
:onError="secondLog"
13+
/>
14+
</template>
15+
<script lang="ts" setup>
16+
import { ref } from "vue"
17+
import { CImage, CImg } from "../index"
18+
19+
const firstRef = ref<{ $el: HTMLImageElement } | null>(null)
20+
const secondRef = ref<{ $el: HTMLImageElement } | null>(null)
21+
22+
const firstLog = (e: any) => {
23+
console.log(1, "Image", e.type, firstRef.value?.$el.currentSrc)
24+
}
25+
26+
const secondLog = (e: any) => {
27+
console.log(2, "Img", e.type, secondRef.value?.$el.currentSrc)
28+
}
29+
</script>

packages/c-image/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './src'

0 commit comments

Comments
 (0)