{"version":3,"file":"Wizard.mjs","names":[],"sources":["../../../src/wizard/Wizard.tsx"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport React, { useEffect } from 'react';\n\nimport { type PolymorphicCommonProps } from '../_common/types';\nimport { Typography } from '../typography';\n\ninterface Step {\n  /** Content displayed as the step label */\n  content: React.ReactNode;\n  /** Explicit status for the step. When set to `error`, the step is rendered in an error state */\n  status?: 'default' | 'error';\n}\n\ninterface BaseWizardProps {\n  /** Layout orientation of the wizard */\n  orientation?: 'horizontal' | 'vertical';\n  /** Visual size of the wizard */\n  size?: 'small' | 'large';\n  /** Additional style */\n  style?: React.CSSProperties;\n  /** Additional class name */\n  className?: string;\n  /** Zero-based index of the active step */\n  activeStepIndex: number;\n  /** Steps to display in the wizard */\n  steps: Step[];\n}\n\ntype HorizontalWizardProps = BaseWizardProps & {\n  orientation: 'horizontal';\n  /** Alignment of labels/content, is set to `middle` for horizontal orientation and can be set to `top` or `middle` for vertical orientation and is not applicable when `orientation` is undefined */\n  alignment?: 'middle';\n};\n\ntype VerticalWizardProps = BaseWizardProps & {\n  orientation: 'vertical';\n  /** Alignment of labels/content, is set to `middle` for horizontal orientation and can be set to `top` or `middle` for vertical orientation and is not applicable when `orientation` is undefined */\n  alignment?: 'top' | 'middle';\n};\n\ntype NonOrientationWizardProps = BaseWizardProps & {\n  orientation: undefined;\n  /** Alignment of labels/content, is set to `middle` for horizontal orientation and can be set to `top` or `middle` for vertical orientation and is not applicable when `orientation` is undefined */\n  alignment?: never;\n};\n\n/**\n * @remarks\n * Where type `Step` is defined as: `{ content: string | React.JSX.Element; status?: 'default' | 'error' }`. To highlight a step as error, set the `status` to `error`.\n */\ntype WizardProps =\n  | HorizontalWizardProps\n  | VerticalWizardProps\n  | NonOrientationWizardProps;\n\nexport const Wizard = <T extends React.ElementType = 'div'>({\n  as,\n  className,\n  style,\n  size = 'large',\n  steps,\n  activeStepIndex,\n  orientation,\n  htmlAttributes,\n  alignment = orientation === 'vertical' ? 'top' : 'middle',\n  ref,\n}: PolymorphicCommonProps<T, WizardProps>) => {\n  useEffect(() => {\n    if (activeStepIndex > steps.length - 1 || activeStepIndex < 0) {\n      console.warn(\n        `[🪡 Needle]: The activeStepIndex in Wizard is out of bounds. The activeStepIndex is ${activeStepIndex} and the number of steps is ${steps.length}.`,\n      );\n    }\n  }, [activeStepIndex, steps.length]);\n\n  switch (size) {\n    case 'small':\n      return (\n        <WizardSmall\n          as={as}\n          orientation={orientation}\n          style={style}\n          className={className}\n          steps={steps}\n          activeStepIndex={activeStepIndex}\n          ref={ref}\n          htmlAttributes={htmlAttributes}\n          alignment={alignment}\n        />\n      );\n    case 'large':\n      return (\n        <WizardLarge\n          as={as}\n          orientation={orientation}\n          style={style}\n          className={className}\n          steps={steps}\n          activeStepIndex={activeStepIndex}\n          ref={ref}\n          htmlAttributes={htmlAttributes}\n          alignment={alignment}\n        />\n      );\n  }\n};\n\nconst getStatus = (activeStepIndex: number, stepIndex: number) =>\n  stepIndex === activeStepIndex\n    ? 'active'\n    : activeStepIndex < stepIndex\n      ? 'incomplete'\n      : 'complete';\n\nconst WizardLarge = <T extends React.ElementType = 'div'>({\n  orientation = 'horizontal',\n  activeStepIndex,\n  steps,\n  as,\n  style,\n  className,\n  htmlAttributes,\n  alignment,\n  ref,\n  ...restProps\n}: PolymorphicCommonProps<T, Omit<WizardProps, 'size'>>) => {\n  const Component: React.ElementType = as || 'div';\n\n  const wizardClasses = classNames(\n    'ndl-wizard',\n    'ndl-wizard-large',\n    {\n      'ndl-horizontal': orientation === 'horizontal',\n      'ndl-vertical': orientation === 'vertical',\n      [`ndl-wizard-align-${alignment}`]: alignment,\n    },\n    className,\n  );\n\n  const componentStyle = {\n    gridTemplateColumns:\n      orientation === 'horizontal'\n        ? `repeat(${steps.length}, 1fr)`\n        : `32px 1fr`,\n\n    gridTemplateRows:\n      orientation === 'vertical' && `repeat(${steps.length}, 1fr)`,\n  };\n\n  const stepClasses = (index: number, step: Step) => {\n    const status = getStatus(activeStepIndex, index);\n\n    return classNames('ndl-wizard-step', {\n      'ndl-horizontal': orientation === 'horizontal',\n      'ndl-vertical': orientation === 'vertical',\n      'ndl-wizard-step-line-right': index < steps.length - 1,\n      'ndl-wizard-step-line-left': index > 0,\n      'ndl-wizard-step-complete': status === 'complete',\n      'ndl-wizard-step-active': status === 'active',\n      'ndl-wizard-step-error': step.status === 'error',\n      [`ndl-wizard-align-${alignment}`]: alignment,\n    });\n  };\n\n  return (\n    <Component\n      className={wizardClasses}\n      style={{ ...style, ...componentStyle }}\n      ref={ref}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      {/* iterate over the steps to render the text content (the first row of the component) */}\n      {steps.map((step, index) => {\n        if (typeof step.content === 'string') {\n          const wizardStepClasses = classNames('ndl-wizard-step-text', {\n            'ndl-vertical': orientation === 'vertical',\n            'ndl-horizontal': orientation === 'horizontal',\n            [`ndl-wizard-align-${alignment}`]: alignment,\n            'ndl-wizard-step-incomplete':\n              getStatus(activeStepIndex, index) === 'incomplete',\n          });\n\n          return (\n            <div key={index} className={wizardStepClasses}>\n              <Typography variant=\"body-large\">{step.content}</Typography>\n            </div>\n          );\n        } else {\n          return <React.Fragment key={index}>{step.content}</React.Fragment>;\n        }\n      })}\n      {/* iterate over the steps to render the circles (iterates again to render the second row of the component) */}\n      {steps.map((step, index) => {\n        return (\n          <div\n            className={stepClasses(index, step)}\n            key={index}\n            style={{\n              gridRow: orientation === 'vertical' ? index + 1 : '',\n            }}\n            aria-current={\n              getStatus(activeStepIndex, index) === 'active'\n                ? 'step'\n                : undefined\n            }\n          >\n            <Circle\n              status={\n                step.status === 'error'\n                  ? 'error'\n                  : getStatus(activeStepIndex, index)\n              }\n              number={index + 1}\n              text={step.content}\n              alignment={alignment}\n            />\n          </div>\n        );\n      })}\n    </Component>\n  );\n};\n\nexport const WizardSmall = <T extends React.ElementType = 'div'>({\n  orientation = 'horizontal',\n  activeStepIndex,\n  steps,\n  as,\n  className,\n  htmlAttributes,\n  style,\n  alignment = 'middle',\n  ref,\n  ...restProps\n}: PolymorphicCommonProps<T, Omit<WizardProps, 'size'>>) => {\n  const Component = as ?? 'div';\n\n  const wizardClasses = classNames(\n    'ndl-wizard',\n    'ndl-wizard-small',\n    {\n      'ndl-horizontal': orientation === 'horizontal',\n      'ndl-vertical': orientation === 'vertical',\n      [`ndl-wizard-align-${alignment}`]: alignment,\n    },\n    className,\n  );\n\n  const stepClasses = (index: number) =>\n    classNames('ndl-wizard-step', {\n      'ndl-horizontal': orientation === 'horizontal',\n      'ndl-vertical': orientation === 'vertical',\n      'ndl-wizard-step-active': getStatus(activeStepIndex, index) === 'active',\n      'ndl-wizard-step-complete':\n        getStatus(activeStepIndex, index) === 'complete',\n      [`ndl-wizard-align-${alignment}`]: alignment,\n    });\n\n  return (\n    <Component\n      className={wizardClasses}\n      style={style}\n      ref={ref}\n      {...restProps}\n      {...htmlAttributes}\n    >\n      <div className=\"ndl-wizard-steps-line\" />\n      {steps.map((step, index) => {\n        return (\n          <div\n            key={index}\n            className={stepClasses(index)}\n            aria-current={\n              getStatus(activeStepIndex, index) === 'active'\n                ? 'step'\n                : undefined\n            }\n          >\n            <div className=\"ndl-wizard-circle\"></div>\n          </div>\n        );\n      })}\n      <div className=\"ndl-wizard-steps-line\" />\n    </Component>\n  );\n};\n\nconst Circle = ({\n  status,\n  number,\n  alignment = 'middle',\n}: {\n  status: 'active' | 'complete' | 'incomplete' | 'error';\n  number: number;\n  text: React.ReactNode;\n  alignment?: 'top' | 'middle';\n}) => {\n  const innerCircleClasses = classNames(\n    'ndl-wizard-circle-inner',\n    `ndl-${status}`,\n  );\n  const outerCircleClasses = classNames('ndl-wizard-circle', {\n    [`ndl-wizard-align-${alignment}`]: alignment,\n  });\n\n  return (\n    <div className={outerCircleClasses}>\n      <svg aria-hidden=\"true\">\n        {status === 'active' && (\n          <g>\n            <circle\n              className=\"ndl-wizard-circle-ring\"\n              style={{ fill: 'transparent', strokeWidth: 2 }}\n              cx=\"16\"\n              cy=\"16\"\n              r=\"14\"\n            />\n          </g>\n        )}\n\n        <circle className={innerCircleClasses} cx=\"16\" cy=\"16\" r=\"12\" />\n        <text\n          x=\"50%\"\n          y=\"50%\"\n          fontSize={14}\n          className=\"ndl-wizard-circle-text\"\n          textAnchor=\"middle\"\n          dominantBaseline=\"middle\"\n          dy=\"0.1em\"\n        >\n          {status === 'error' ? '!' : number}\n        </text>\n      </svg>\n    </div>\n  );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuIE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;CAsGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;AAlLF,MAAa,UAA+C,EAC1D,IACA,WACA,OACA,OAAO,SACP,OACA,iBACA,aACA,gBACA,YAAY,gBAAgB,aAAa,QAAQ,UACjD,UAC4C;CAC5C,gBAAgB;EACd,IAAI,kBAAkB,MAAM,SAAS,KAAK,kBAAkB,GAC1D,QAAQ,KACN,uFAAuF,gBAAgB,8BAA8B,MAAM,OAAO,EACpJ;CAEJ,GAAG,CAAC,iBAAiB,MAAM,MAAM,CAAC;CAElC,QAAQ,MAAR;EACE,KAAK,SACH,OACE,oBAAC,aAAD;GACM;GACS;GACN;GACI;GACJ;GACU;GACZ;GACW;GACL;EACZ,CAAA;EAEL,KAAK,SACH,OACE,oBAAC,aAAD;GACM;GACS;G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