Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useTextColor hook #1729

Closed
m0ksem opened this issue May 5, 2022 · 9 comments · Fixed by #1769
Closed

useTextColor hook #1729

m0ksem opened this issue May 5, 2022 · 9 comments · Fixed by #1769
Assignees
Labels
feature Something useful to end user good first issue Right issue if you're new to vuestic

Comments

@m0ksem
Copy link
Contributor

m0ksem commented May 5, 2022

Let's have hook, that requires one prop:

  • textColor - component's text color

Returns

textColorComputed - returns textColor prop (if passed) or automatically calculated color

Must be used across components like VaButton, VaChip, VaCheckbox, VaSwitch, VaCollapse etc.

const { textColorComputed }  = useTextColor(props.background)
// or
const { textColorComputed }  = useTextColor(props.color) // component color

Text Color must be taken from getCurrentInstance

export const useTextColor = (textBackground: string | Ref<string>) => {
   const { props } = getCurrentInstance()!

  const textColor = computed(() => props.textColor || getTextColor(unref(textBackground)))
   
   return { textColor }
}
@m0ksem m0ksem added feature Something useful to end user good first issue Right issue if you're new to vuestic labels May 5, 2022
@Sadnessa
Copy link
Contributor

Sadnessa commented May 5, 2022

Hello. Can I try this task, please?

@asvae asvae mentioned this issue May 5, 2022
5 tasks
@aluarius
Copy link
Contributor

aluarius commented May 5, 2022

See also #1295

@m0ksem
Copy link
Contributor Author

m0ksem commented May 5, 2022

Take a notice that outlined VaAlert has color from color prop by default, but it must change to text-color if it provided.

https://vuestic.dev/en/ui-elements/alert#different-styles
In this example we should be able to pass textColor to outlined VaAlert, so it can have yellow outline, but black text.

@Derranion
Copy link
Contributor

Should set text color for VaAlert when border prop is active.

@Derranion
Copy link
Contributor

Derranion commented May 5, 2022

Take a notice that outlined VaAlert has color from color prop by default, but it must change to text-color if it provided.

https://vuestic.dev/en/ui-elements/alert#different-styles In this example we should be able to pass textColor to outlined VaAlert, so it can have yellow outline, but black text.

Hey @m0ksem
This looks like another separate task though - to add textColor prop for VaAlert and related docs.
Because unlike components that were listed in the initial task description VaAlert does not have this prop.

@m0ksem
Copy link
Contributor Author

m0ksem commented May 5, 2022

Take a notice that outlined VaAlert has color from color prop by default, but it must change to text-color if it provided.

https://vuestic.dev/en/ui-elements/alert#different-styles In this example we should be able to pass textColor to outlined VaAlert, so it can have yellow outline, but black text.

Hey @m0ksem
This looks like another separate task though - to add textColor prop for VaAlert and related docs.
Because unlike components that were listed in the initial description it does not have this prop.

Alert doesn't have the prop, but I have to.

@m0ksem
Copy link
Contributor Author

m0ksem commented May 5, 2022

I'm thinking how can we deal with components like date picker. It has a transparent background, so we are not able to calculate text color automatically.

As a workaround, we can go through all component parent elements until we find element with background style set. Handle reactivity with MutationObserver. Not sure how it will impact performance.

@Derranion
Copy link
Contributor

We decided to create separate tasks to add textColor prop to VaAlert and to improve automatically selected color algorithm.

By the way @m0ksem here are some examples of parents traversing algorithms to get the real background-color, could be useful:
https://stackoverflow.com/questions/12576084/getting-the-real-background-color-of-an-element

That's why @Sadnessa please feel free to ignore these comments and continue with the initial task, thanks (:

@m0ksem
Copy link
Contributor Author

m0ksem commented May 5, 2022

Yes. Let's have useTextColor hook, we can improve it later with this PR #1736.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Something useful to end user good first issue Right issue if you're new to vuestic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants