-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: condense acct * fix: watch parent element size --------- Co-authored-by: syuilo <[email protected]>
- Loading branch information
1 parent
5349899
commit 2cfed33
Showing
5 changed files
with
117 additions
and
2 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
39 changes: 39 additions & 0 deletions
39
packages/frontend/src/components/global/MkCondensedLine.stories.impl.ts
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,39 @@ | ||
/* eslint-disable @typescript-eslint/explicit-function-return-type */ | ||
import { StoryObj } from '@storybook/vue3'; | ||
import MkCondensedLine from './MkCondensedLine.vue'; | ||
export const Default = { | ||
render(args) { | ||
return { | ||
components: { | ||
MkCondensedLine, | ||
}, | ||
setup() { | ||
return { | ||
args, | ||
}; | ||
}, | ||
computed: { | ||
props() { | ||
return { | ||
...this.args, | ||
}; | ||
}, | ||
}, | ||
template: '<MkCondensedLine>{{ props.text }}</MkCondensedLine>', | ||
}; | ||
}, | ||
args: { | ||
text: 'This is a condensed line.', | ||
}, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
} satisfies StoryObj<typeof MkCondensedLine>; | ||
export const ContainerIs100px = { | ||
...Default, | ||
decorators: [ | ||
() => ({ | ||
template: '<div style="width: 100px;"><story/></div>', | ||
}), | ||
], | ||
} satisfies StoryObj<typeof MkCondensedLine>; |
56 changes: 56 additions & 0 deletions
56
packages/frontend/src/components/global/MkCondensedLine.vue
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,56 @@ | ||
<template> | ||
<span :class="$style.container"> | ||
<span ref="content" :class="$style.content"> | ||
<slot/> | ||
</span> | ||
</span> | ||
</template> | ||
|
||
<script lang="ts"> | ||
const contentSymbol = Symbol(); | ||
const observer = new ResizeObserver((entries) => { | ||
for (const entry of entries) { | ||
const content = (entry.target[contentSymbol] ? entry.target : entry.target.firstElementChild) as HTMLSpanElement; | ||
const container = content.parentElement as HTMLSpanElement; | ||
const contentWidth = content.getBoundingClientRect().width; | ||
const containerWidth = container.getBoundingClientRect().width; | ||
container.style.transform = `scaleX(${Math.min(1, containerWidth / contentWidth)})`; | ||
} | ||
}); | ||
</script> | ||
|
||
<script setup lang="ts"> | ||
import { ref, watch } from 'vue'; | ||
const content = ref<HTMLSpanElement>(); | ||
watch(content, (value, oldValue) => { | ||
if (oldValue) { | ||
delete oldValue[contentSymbol]; | ||
observer.unobserve(oldValue); | ||
if (oldValue.parentElement) { | ||
observer.unobserve(oldValue.parentElement); | ||
} | ||
} | ||
if (value) { | ||
value[contentSymbol] = contentSymbol; | ||
observer.observe(value); | ||
if (value.parentElement) { | ||
observer.observe(value.parentElement); | ||
} | ||
} | ||
}); | ||
</script> | ||
|
||
<style module lang="scss"> | ||
.container { | ||
display: inline-block; | ||
width: 100%; | ||
transform-origin: 0; | ||
} | ||
.content { | ||
display: inline-block; | ||
white-space: nowrap; | ||
} | ||
</style> |
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