{"version":3,"sources":["../src/createArrowStyles.ts"],"sourcesContent":["import { tokens } from '@fluentui/react-theme';\nimport type { GriffelStyle } from '@griffel/react';\n\n/**\n * Options parameter for the createArrowStyles function\n *\n * @internal\n */\nexport type CreateArrowStylesOptions = {\n  /**\n   * The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.\n   *\n   * This can be undefined to leave out the arrow size styles. You must then add styles created by\n   * createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.\n   */\n  arrowHeight: number | undefined;\n\n  /**\n   * The borderWidth of the arrow. Should be the same borderWidth as the parent element.\n   *\n   * @defaultvalue 1px\n   */\n  borderWidth?: GriffelStyle['borderBottomWidth'];\n\n  /**\n   * The borderStyle for the arrow. Should be the same borderStyle as the parent element.\n   *\n   * @defaultvalue solid\n   */\n  borderStyle?: GriffelStyle['borderBottomStyle'];\n\n  /**\n   * The borderColor of the arrow. Should be the same borderColor as the parent element.\n   *\n   * @defaultvalue tokens.colorTransparentStroke\n   */\n  borderColor?: GriffelStyle['borderBottomColor'];\n};\n\n/**\n * Helper that creates a makeStyles rule for an arrow element.\n * For runtime arrow size toggling simply create extra classnames to apply to the arrow element\n *\n * ```ts\n *   makeStyles({\n *     arrowWithSize: createArrowStyles({ arrowHeight: 6 }),\n *\n *     arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),\n *     mediumArrow: createArrowHeightStyles(4),\n *     smallArrow: createArrowHeightStyles(2),\n *   })\n *   ...\n *\n *   state.arrowWithSize.className = styles.arrowWithSize;\n *   state.arrowWithoutSize.className = mergeClasses(\n *     styles.arrowWithoutSize,\n *     state.smallArrow && styles.smallArrow,\n *     state.mediumArrow && styles.mediumArrow,\n *   )\n * ```\n *\n * @internal\n */\nexport function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle {\n  const {\n    arrowHeight,\n    borderWidth = '1px',\n    borderStyle = 'solid',\n    borderColor = tokens.colorTransparentStroke,\n  } = options;\n\n  return {\n    boxSizing: 'border-box',\n    position: 'absolute',\n    zIndex: -1,\n\n    ...(arrowHeight && createArrowHeightStyles(arrowHeight)),\n\n    backgroundColor: 'inherit',\n    backgroundClip: 'content-box',\n\n    borderBottomLeftRadius: `${tokens.borderRadiusSmall} /* @noflip */`,\n    transform: 'rotate(var(--fui-positioning-arrow-angle)) /* @noflip */',\n\n    height: 'var(--fui-positioning-arrow-height)',\n    width: 'var(--fui-positioning-arrow-height)',\n\n    '::before': {\n      content: '\"\"',\n\n      display: 'block',\n      backgroundColor: 'inherit',\n      margin: `-${borderWidth}`,\n      width: '100%',\n      height: '100%',\n\n      border: `${borderWidth} ${borderStyle} ${borderColor}`,\n      borderBottomLeftRadius: `${tokens.borderRadiusSmall} /* @noflip */`,\n\n      clipPath: 'polygon(0% 0%, 100% 100%, 0% 100%)',\n    },\n\n    // Popper sets data-popper-placement on the root element, which is used to align the arrow\n    ':global([data-popper-placement^=\"top\"])': {\n      bottom: 'var(--fui-positioning-arrow-offset)',\n      '--fui-positioning-arrow-angle': '-45deg',\n    },\n    ':global([data-popper-placement^=\"right\"])': {\n      left: `var(--fui-positioning-arrow-offset) /* @noflip */`,\n      '--fui-positioning-arrow-angle': '45deg',\n    },\n    ':global([data-popper-placement^=\"bottom\"])': {\n      top: 'var(--fui-positioning-arrow-offset)',\n      '--fui-positioning-arrow-angle': '135deg',\n    },\n    ':global([data-popper-placement^=\"left\"])': {\n      right: `var(--fui-positioning-arrow-offset) /* @noflip */`,\n      '--fui-positioning-arrow-angle': '225deg',\n    },\n  };\n}\n\n/**\n * Creates CSS styles to size the arrow created by createArrowStyles to the given height.\n *\n * Use this when you need to create classes for several different arrow sizes. If you only need a\n * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.\n *\n * @internal\n */\nexport function createArrowHeightStyles(arrowHeight: number): GriffelStyle {\n  // The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.\n  // Multiply the triangle's height by sqrt(2) to get length of its edges.\n  const edgeLength = 1.414 * arrowHeight;\n\n  return {\n    '--fui-positioning-arrow-height': `${edgeLength}px`,\n    '--fui-positioning-arrow-offset': `${(edgeLength / 2) * -1}px`,\n  };\n}\n"],"names":["tokens","createArrowStyles","options","arrowHeight","borderWidth","borderStyle","borderColor","colorTransparentStroke","boxSizing","position","zIndex","createArrowHeightStyles","backgroundColor","backgroundClip","borderBottomLeftRadius","borderRadiusSmall","transform","height","width","content","display","margin","border","clipPath","bottom","left","top","right","edgeLength"],"mappings":";;;;;;;;;;;QAkIgBW;;;QAnEAV;;;;4BA/DO,wBAAwB;AA+DxC,2BAA2BC,OAAiC;IACjE,MAAM,EACJC,WAAW,EACXC,cAAc,KAAK,EACnBC,cAAc,OAAO,EACrBC,cAAcN,kBAAAA,CAAOO,sBAAsB,EAC5C,GAAGL;IAEJ,OAAO;QACLM,WAAW;QACXC,UAAU;QACVC,QAAQ,CAAC;QAET,GAAIP,eAAeQ,wBAAwBR,YAAY;QAEvDS,iBAAiB;QACjBC,gBAAgB;QAEhBC,wBAAwB,GAAGd,kBAAAA,CAAOe,iBAAiB,CAAC,cAAc,CAAC;QACnEC,WAAW;QAEXC,QAAQ;QACRC,OAAO;QAEP,YAAY;YACVC,SAAS;YAETC,SAAS;YACTR,iBAAiB;YACjBS,QAAQ,CAAC,CAAC,EAAEjB,aAAa;YACzBc,OAAO;YACPD,QAAQ;YAERK,QAAQ,GAAGlB,YAAY,CAAC,EAAEC,YAAY,CAAC,EAAEC,aAAa;YACtDQ,wBAAwB,GAAGd,kBAAAA,CAAOe,iBAAiB,CAAC,cAAc,CAAC;YAEnEQ,UAAU;QACZ;QAEA,0FAA0F;QAC1F,2CAA2C;YACzCC,QAAQ;YACR,iCAAiC;QACnC;QACA,6CAA6C;YAC3CC,MAAM,CAAC,iDAAiD,CAAC;YACzD,iCAAiC;QACnC;QACA,8CAA8C;YAC5CC,KAAK;YACL,iCAAiC;QACnC;QACA,4CAA4C;YAC1CC,OAAO,CAAC,iDAAiD,CAAC;YAC1D,iCAAiC;QACnC;IACF;AACF;AAUO,iCAAiCxB,WAAmB;IACzD,qGAAqG;IACrG,wEAAwE;IACxE,MAAMyB,aAAa,QAAQzB;IAE3B,OAAO;QACL,kCAAkC,GAAGyB,WAAW,EAAE,CAAC;QACnD,kCAAkC,GAAIA,aAAa,IAAK,CAAC,EAAE,EAAE,CAAC;IAChE;AACF"}