Skip to content

cas-298 - add component and ref to calculate width#229

Merged
dbslone merged 4 commits intomainfrom
germanurrustarazu/cas-298
Jul 22, 2022
Merged

cas-298 - add component and ref to calculate width#229
dbslone merged 4 commits intomainfrom
germanurrustarazu/cas-298

Conversation

@germanurrus
Copy link
Copy Markdown
Contributor

@germanurrus germanurrus commented Jul 22, 2022

Shrink author address to fit in container:

Screen.Recording.2022-07-22.at.12.25.49.mov

>
<div
className="columns is-mobile p-0 m-0 mb-5 small-text"
ref={containerRef}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creating ref so children knows parent size to know if it needs to shrink

/>
</div>
<div className="column px-2 py-0 is-flex flex-1 is-align-items-center">
{creatorAddr}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't use something like:

max-width: 150px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: inline-block;

bc size depends on parent component and setting a max with at this level doesn't work, component needs to know parent size to shrink or not

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another strategy do this with text-overflow would be to set maxWidth dynamically with javascript using refs etc but I think truncating an address by removing the middle chunks is much better than removing the end (people often use the first/last four characters of an address as a quick identifier)

Copy link
Copy Markdown
Contributor

@mannynotfound mannynotfound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good enough for now given how minor of an issue it is but width could be calculated more dynamically

const { width } = useWindowDimensions();

useEffect(() => {
if (ref?.current.clientWidth <= 223 && creatorAddr === addr) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this number might vary depending on the contents of the address, for example if there is a lot of W (the widest letter) vs a lot of I and 1 etc - probably works well enough for most addresses though or maybe add a bit of extra padding (250?) in case of longer addresses. Otherwise youll want to give the address white-space: nowrap and then calculate if the width of the address is greater than the width of the parent container and then truncate

/>
</div>
<div className="column px-2 py-0 is-flex flex-1 is-align-items-center">
{creatorAddr}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another strategy do this with text-overflow would be to set maxWidth dynamically with javascript using refs etc but I think truncating an address by removing the middle chunks is much better than removing the end (people often use the first/last four characters of an address as a quick identifier)

@dbslone dbslone merged commit 52d4520 into main Jul 22, 2022
@dbslone dbslone deleted the germanurrustarazu/cas-298 branch July 22, 2022 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants