Skip to content

Commit

Permalink
feat: picture component moved to hoppscotch-ui (hoppscotch#3032)
Browse files Browse the repository at this point in the history
  • Loading branch information
anwarulislam authored and AndrewBastin committed May 11, 2023
1 parent f43b6e7 commit 09d1663
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 145 deletions.
2 changes: 2 additions & 0 deletions packages/hoppscotch-common/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ declare module '@vue/runtime-core' {
HoppSmartItem: typeof import('@hoppscotch/ui')['HoppSmartItem']
HoppSmartLink: typeof import('@hoppscotch/ui')['HoppSmartLink']
HoppSmartModal: typeof import('@hoppscotch/ui')['HoppSmartModal']
HoppSmartPicture: typeof import('@hoppscotch/ui')['HoppSmartPicture']
HoppSmartProgressRing: typeof import('@hoppscotch/ui')['HoppSmartProgressRing']
HoppSmartRadioGroup: typeof import('@hoppscotch/ui')['HoppSmartRadioGroup']
HoppSmartSlideOver: typeof import('@hoppscotch/ui')['HoppSmartSlideOver']
Expand Down Expand Up @@ -164,6 +165,7 @@ declare module '@vue/runtime-core' {
SmartItem: typeof import('./../../hoppscotch-ui/src/components/smart/Item.vue')['default']
SmartLink: typeof import('./../../hoppscotch-ui/src/components/smart/Link.vue')['default']
SmartModal: typeof import('./../../hoppscotch-ui/src/components/smart/Modal.vue')['default']
SmartPicture: typeof import('./../../hoppscotch-ui/src/components/smart/Picture.vue')['default']
SmartProgressRing: typeof import('./../../hoppscotch-ui/src/components/smart/ProgressRing.vue')['default']
SmartRadio: typeof import('./../../hoppscotch-ui/src/components/smart/Radio.vue')['default']
SmartRadioGroup: typeof import('./../../hoppscotch-ui/src/components/smart/RadioGroup.vue')['default']
Expand Down
4 changes: 2 additions & 2 deletions packages/hoppscotch-common/src/components/app/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
theme="popover"
:on-shown="() => tippyActions.focus()"
>
<ProfilePicture
<HoppSmartPicture
v-if="currentUser.photoURL"
v-tippy="{
theme: 'tooltip',
Expand All @@ -144,7 +144,7 @@
network.isOnline ? 'bg-green-500' : 'bg-red-500'
"
/>
<ProfilePicture
<HoppSmartPicture
v-else
v-tippy="{ theme: 'tooltip' }"
:title="
Expand Down
87 changes: 0 additions & 87 deletions packages/hoppscotch-common/src/components/profile/Picture.vue

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:key="`member-${index}`"
class="inline-flex"
>
<ProfilePicture
<HoppSmartPicture
v-if="member.user.photoURL"
v-tippy="{ theme: 'tooltip' }"
:url="member.user.photoURL"
Expand All @@ -14,7 +14,7 @@
class="ring-primary ring-2"
@click="handleClick()"
/>
<ProfilePicture
<HoppSmartPicture
v-else
v-tippy="{ theme: 'tooltip' }"
:title="getUserName(member)"
Expand Down
4 changes: 2 additions & 2 deletions packages/hoppscotch-common/src/pages/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
></div>
<div class="flex flex-col justify-between px-4 space-y-8 md:flex-row">
<div class="flex items-end">
<ProfilePicture
<HoppSmartPicture
v-if="currentUser.photoURL"
:url="currentUser.photoURL"
:alt="
Expand All @@ -44,7 +44,7 @@
size="16"
rounded="lg"
/>
<ProfilePicture
<HoppSmartPicture
v-else
:initial="currentUser.displayName || currentUser.email"
rounded="lg"
Expand Down
4 changes: 2 additions & 2 deletions packages/hoppscotch-sh-admin/src/components/app/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
arrow
:on-shown="() => tippyActions!.focus()"
>
<ProfilePicture
<HoppSmartPicture
v-if="currentUser.photoURL"
v-tippy="{
theme: 'tooltip',
Expand All @@ -37,7 +37,7 @@
:alt="currentUser.displayName ?? 'No Name'"
:title="currentUser.displayName ?? currentUser.email ?? 'No Name'"
/>
<ProfilePicture
<HoppSmartPicture
v-else
v-tippy="{ theme: 'tooltip' }"
:title="currentUser.displayName ?? currentUser.email ?? 'No Name'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,55 +33,40 @@
</div>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue';
<script setup lang="ts">
withDefaults(
defineProps<{
url: string
alt: string
indicator: boolean
indicatorStyles: string
rounded: string
size: string
initial: string | undefined | null
}>(),
{
url: "",
alt: "Profile picture",
indicator: false,
indicatorStyles: "bg-green-500",
rounded: "full",
size: "5",
initial: "",
}
)
export default defineComponent({
props: {
url: {
type: String,
default: '',
},
alt: {
type: String,
default: 'Profile picture',
},
indicator: {
type: Boolean,
default: false,
},
indicatorStyles: {
type: String,
default: 'bg-green-500',
},
rounded: {
type: String,
default: 'full',
},
size: {
type: String,
default: '5',
},
initial: {
type: String as PropType<string | undefined | null>,
default: '',
},
},
methods: {
toHex(initial: string) {
let hash = 0;
if (initial.length === 0) return hash;
for (let i = 0; i < initial.length; i++) {
hash = initial.charCodeAt(i) + ((hash << 5) - hash);
hash = hash & hash;
}
let color = '#';
for (let i = 0; i < 3; i++) {
const value = (hash >> (i * 8)) & 255;
color += `00${value.toString(16)}`.slice(-2);
}
return color;
},
},
});
const toHex = (initial: string) => {
let hash = 0
if (initial.length === 0) return hash
for (let i = 0; i < initial.length; i++) {
hash = initial.charCodeAt(i) + ((hash << 5) - hash)
hash = hash & hash
}
let color = "#"
for (let i = 0; i < 3; i++) {
const value = (hash >> (i * 8)) & 255
color += `00${value.toString(16)}`.slice(-2)
}
return color
}
</script>
1 change: 1 addition & 0 deletions packages/hoppscotch-ui/src/components/smart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export { default as HoppSmartTabs } from "./Tabs.vue"
export { default as HoppSmartToggle } from "./Toggle.vue"
export { default as HoppSmartWindow } from "./Window.vue"
export { default as HoppSmartWindows } from "./Windows.vue"
export { default as HoppSmartPicture } from "./Picture.vue"

0 comments on commit 09d1663

Please sign in to comment.