carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 1.15 kB
JavaScript
import{jsxs as e,Fragment as r,jsx as t}from"react/jsx-runtime";import{useRef as o}from"react";import{useStrictFlatTableContext as n}from"../__internal__/strict-flat-table.context.js";import{Typography as a}from"../../typography/typography.component.js";import l from"../../../__internal__/utils/helpers/events/events.js";import s from"../../../__internal__/utils/helpers/guid/index.js";import i from"../../../hooks/__internal__/useLocale/useLocale.js";import c from"../../icon/icon.component.js";import m from"./sort.style.js";const p=({children:p,onClick:d,sortType:_,accessibleName:u,"data-element":h,"data-role":f})=>{const y=o(s()),j=i(),{colorTheme:b}=n();return e(r,{children:[t(a,{screenReaderOnly:!0,id:y.current,children:u||j.sort.accessibleName(p,_)}),e(m,{"aria-labelledby":y.current,colorTheme:b,"data-component":"sort","data-element":h,"data-role":f,onClick:d,onKeyDown:e=>l.isEnterOrSpaceKey(e)?(e.preventDefault(),null==d?void 0:d()):null,children:[t("span",{children:p}),_?t(c,{"data-element":"sort-icon",type:"ascending"===_?"sort_up":"sort_down"}):t("span",{"data-role":"sort-placeholder"})]})]})};export{p as Sort,p as default};