-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from appwrite/feat-id-component
feat: new id component
- Loading branch information
Showing
30 changed files
with
148 additions
and
213 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<script lang="ts"> | ||
import { Copy } from '.'; | ||
export let value: string; | ||
export let event: string = null; | ||
function truncateText(node: HTMLElement) { | ||
const MAX_TRIES = 100; | ||
let originalText = node.textContent; | ||
function checkOverflow() { | ||
node.textContent = originalText; | ||
if (node.scrollWidth > node.clientWidth) { | ||
let truncatedText = originalText; | ||
let tries = 0; | ||
while ( | ||
node.scrollWidth > node.clientWidth && | ||
truncatedText.length > 0 && | ||
tries < MAX_TRIES | ||
) { | ||
tries++; | ||
if (truncatedText.includes('…')) { | ||
const [left, right] = truncatedText.split('…'); | ||
truncatedText = `${left.slice(0, -1)}…${right.slice(1)}`; | ||
} else { | ||
const left = truncatedText.slice(0, truncatedText.length / 2); | ||
const right = truncatedText.slice(truncatedText.length / 2); | ||
truncatedText = `${left.slice(0, -1)}…${right.slice(1)}`; | ||
} | ||
node.textContent = truncatedText; | ||
} | ||
} | ||
} | ||
checkOverflow(); | ||
window.addEventListener('resize', checkOverflow); | ||
return { | ||
update() { | ||
originalText = node.textContent; | ||
checkOverflow(); | ||
}, | ||
destroy() { | ||
window.removeEventListener('resize', checkOverflow); | ||
} | ||
}; | ||
} | ||
</script> | ||
|
||
<div | ||
class="interactive-text-output is-buttons-on-top" | ||
style:min-inline-size="0" | ||
style:display="inline-flex"> | ||
<span | ||
style:white-space="nowrap" | ||
class="text u-line-height-1-5" | ||
style:overflow="hidden" | ||
use:truncateText> | ||
<slot /> | ||
</span> | ||
<div class="interactive-text-output-buttons"> | ||
<Copy {value} {event}> | ||
<button class="interactive-text-output-button is-hidden" aria-label="copy text"> | ||
<span class="icon-duplicate" aria-hidden="true" /> | ||
</button> | ||
</Copy> | ||
</div> | ||
</div> |
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
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
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
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
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
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
Oops, something went wrong.