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

[Feat?]: create useCanvasColors hook #734

Closed
7 tasks done
caseybaggz opened this issue Nov 21, 2024 · 0 comments · Fixed by #737
Closed
7 tasks done

[Feat?]: create useCanvasColors hook #734

caseybaggz opened this issue Nov 21, 2024 · 0 comments · Fixed by #737
Assignees
Labels
enhancement New feature or request

Comments

@caseybaggz
Copy link
Collaborator

caseybaggz commented Nov 21, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

When working with canvas related libraries, in order to use Cerb colors you have to hack around the document body. We should provide a hook that makes this easier for the user.

Create a new hook called useChartColors with the use client directive at the top of

  • the file
  • Create an useReducer<{ tokenName: string }> to hold the value
  • Add a useEffect to put your document canvas code in which will update the state
  • return a useMemo of the state - unless you are doing useReducer, then you don't need that
  • Use the hook to get the values for the chart customization in the client component

Examples 🌈

Goal to have an API like this

'use client'

const colorsToGet = [
  'dataViz.diverging.50',
  'dataViz.diverging.100',
  'dataViz.diverging.200'
]

function SomeFeatureWithACanvasItem() {
  const [cavasSettings, setCanvasSettings] = useState(initialSettings)
  const colors = useCanvasColors(colorsToGet)

  useEffect(() => {
     setCanvasSettings((prev) => ({
         ...prev,
         someSetting: {
             bgColor: colors[colorsToGet[0]]
         },
         anotherSetting: {
             bgColor: colors[colorsToGet[1]]
         },        
     }))
  }, [colors])

  return (
     <SomeCanvasThing settings={canvasSettings} />
  )
}

Motivation 🔦

No response

@caseybaggz caseybaggz added the enhancement New feature or request label Nov 21, 2024
@caseybaggz caseybaggz self-assigned this Nov 21, 2024
@caseybaggz caseybaggz linked a pull request Nov 21, 2024 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant