Skip to content

[docs] Dynamic value is used in sx prop incorrectly #45904

Open
@thiisiriya

Description

@thiisiriya

Related page

https://v6.mui.com/material-ui/migration/migrating-to-pigment-css/#sx-prop

Kind of issue

Broken demo

Issue description

Docks suggest "If a value depends on a variable, you need to move it to a CSS variable inside inline styles." but AFTER example includes the usage of a dynamic value in sx which actually throws an error:

<div>
  {items.map((item, index) => (
    <Box
      key={index}
      sx={{
        borderRadius: '50%',
        width: `max(6px - var(--offset), 3px)`,
        height: `max(6px - var(--offset), 3px)`,
        --> bgcolor: index === 0 ? 'primary.solidBg' : 'background.level3', <--
      }}
      style={{
        '--offset': `${index}px`,
      }}
    />
  ))}
</div>

I think the demo should be overwritten leveraging array syntax like this:

<div>
  {items.map((item, index) => (
    <Box
      key={index}
      sx={[
        {
          borderRadius: '50%',
          width: `max(6px - var(--offset), 3px)`,
          height: `max(6px - var(--offset), 3px)`,
        },
        index === 0 ? { backgroundColor: 'primary.solidBg' } : { backgroundColor: 'background.level3' }
      ]}
      style={{
        '--offset': `${index}px`,
      }}
    />
  ))}
</div>

Context

No response

Search keywords: pigment-css

Metadata

Metadata

Assignees

Labels

bug 🐛Something doesn't workdocsImprovements or additions to the documentationready to takeHelp wanted. Guidance available. There is a high chance the change will be acceptedsupport: docs-feedbackFeedback from documentation page

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions