@primer/components 0.0.0-20219416616 → 0.0.0-20219421241

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/browser.esm.js +768 -714
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +409 -355
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/Token/Token.d.ts +14 -0
  7. package/lib/Token/Token.js +76 -0
  8. package/lib/Token/TokenBase.d.ts +16 -0
  9. package/lib/Token/TokenBase.js +90 -0
  10. package/lib/Token/TokenLabel.d.ts +14 -0
  11. package/lib/Token/TokenLabel.js +141 -0
  12. package/lib/Token/TokenProfile.d.ts +7 -0
  13. package/lib/Token/TokenProfile.js +50 -0
  14. package/lib/Token/_RemoveTokenButton.d.ts +3 -0
  15. package/lib/Token/_RemoveTokenButton.js +44 -0
  16. package/lib/Token/_tokenButtonUtils.d.ts +10 -0
  17. package/lib/Token/_tokenButtonUtils.js +42 -0
  18. package/lib/Token/index.d.ts +3 -0
  19. package/lib/Token/index.js +31 -0
  20. package/lib/index.d.ts +1 -0
  21. package/lib/index.js +20 -0
  22. package/lib-esm/Token/Token.d.ts +14 -0
  23. package/lib-esm/Token/Token.js +57 -0
  24. package/lib-esm/Token/TokenBase.d.ts +16 -0
  25. package/lib-esm/Token/TokenBase.js +70 -0
  26. package/lib-esm/Token/TokenLabel.d.ts +14 -0
  27. package/lib-esm/Token/TokenLabel.js +121 -0
  28. package/lib-esm/Token/TokenProfile.d.ts +7 -0
  29. package/lib-esm/Token/TokenProfile.js +29 -0
  30. package/lib-esm/Token/_RemoveTokenButton.d.ts +3 -0
  31. package/lib-esm/Token/_RemoveTokenButton.js +29 -0
  32. package/lib-esm/Token/_tokenButtonUtils.d.ts +10 -0
  33. package/lib-esm/Token/_tokenButtonUtils.js +26 -0
  34. package/lib-esm/Token/index.d.ts +3 -0
  35. package/lib-esm/Token/index.js +3 -0
  36. package/lib-esm/index.d.ts +1 -0
  37. package/lib-esm/index.js +1 -0
  38. package/package.json +4 -2
package/lib/index.js CHANGED
@@ -441,6 +441,24 @@ Object.defineProperty(exports, "Timeline", {
441
441
  return _Timeline.default;
442
442
  }
443
443
  });
444
+ Object.defineProperty(exports, "Token", {
445
+ enumerable: true,
446
+ get: function () {
447
+ return _Token.default;
448
+ }
449
+ });
450
+ Object.defineProperty(exports, "TokenLabel", {
451
+ enumerable: true,
452
+ get: function () {
453
+ return _Token.TokenLabel;
454
+ }
455
+ });
456
+ Object.defineProperty(exports, "TokenProfile", {
457
+ enumerable: true,
458
+ get: function () {
459
+ return _Token.TokenProfile;
460
+ }
461
+ });
444
462
  Object.defineProperty(exports, "Tooltip", {
445
463
  enumerable: true,
446
464
  get: function () {
@@ -586,6 +604,8 @@ var _Text = _interopRequireDefault(require("./Text"));
586
604
 
587
605
  var _Timeline = _interopRequireDefault(require("./Timeline"));
588
606
 
607
+ var _Token = _interopRequireWildcard(require("./Token"));
608
+
589
609
  var _Tooltip = _interopRequireDefault(require("./Tooltip"));
590
610
 
591
611
  var _Truncate = _interopRequireDefault(require("./Truncate"));
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { TokenBaseProps } from './TokenBase';
3
+ export interface TokenProps extends TokenBaseProps {
4
+ /**
5
+ * A function that renders a component before the token text
6
+ */
7
+ leadingVisual?: React.FunctionComponent<any>;
8
+ /**
9
+ * Whether the remove button should be rendered in the token
10
+ */
11
+ hideRemoveButton?: boolean;
12
+ }
13
+ declare const Token: React.ForwardRefExoticComponent<Pick<TokenProps, "sizes" | "color" | "content" | "height" | "translate" | "width" | "hidden" | "children" | "value" | "cite" | "data" | "form" | "label" | "slot" | "span" | "style" | "summary" | "title" | "pattern" | "text" | "list" | "default" | "type" | "name" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "start" | "step" | "wrap" | "open" | "max" | "media" | "method" | "min" | "target" | "crossOrigin" | "href" | "classID" | "useMap" | "wmode" | "download" | "hrefLang" | "rel" | "alt" | "coords" | "shape" | "autoPlay" | "controls" | "loop" | "mediaGroup" | "muted" | "playsInline" | "preload" | "src" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "dateTime" | "acceptCharset" | "action" | "autoComplete" | "encType" | "noValidate" | "manifest" | "allowFullScreen" | "allowTransparency" | "frameBorder" | "marginHeight" | "marginWidth" | "sandbox" | "scrolling" | "seamless" | "srcDoc" | "srcSet" | "async" | "accept" | "capture" | "checked" | "maxLength" | "minLength" | "multiple" | "readOnly" | "required" | "challenge" | "keyType" | "keyParams" | "htmlFor" | "as" | "integrity" | "charSet" | "httpEquiv" | "high" | "low" | "optimum" | "reversed" | "selected" | "defer" | "nonce" | "scoped" | "cellPadding" | "cellSpacing" | "colSpan" | "headers" | "rowSpan" | "scope" | "cols" | "rows" | "kind" | "srcLang" | "poster" | "variant" | "leadingVisual" | "handleRemove" | "isSelected" | "hideRemoveButton"> & React.RefAttributes<HTMLAnchorElement | HTMLButtonElement | HTMLSpanElement>>;
14
+ export default Token;
@@ -0,0 +1,57 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React, { forwardRef } from 'react';
4
+ import styled from 'styled-components';
5
+ import { get } from '../constants';
6
+ import TokenBase, { isTokenInteractive } from './TokenBase';
7
+ import RemoveTokenButton from './_RemoveTokenButton';
8
+ const tokenBorderWidthPx = 1;
9
+ const DefaultTokenStyled = styled(TokenBase).withConfig({
10
+ displayName: "Token__DefaultTokenStyled",
11
+ componentId: "sc-1dg52pw-0"
12
+ })(["background-color:", ";border-color:", ";border-style:solid;border-width:1px;color:", ";max-width:100%;padding-right:", ";&:hover{background-color:", ";box-shadow:", ";color:", ";}"], get('colors.neutral.subtle'), props => props.isSelected ? get('colors.fg.default') : get('colors.border.subtle'), props => props.isSelected ? get('colors.fg.default') : get('colors.fg.muted'), props => !props.hideRemoveButton ? 0 : undefined, props => isTokenInteractive(props) ? get('colors.neutral.muted') : undefined, props => isTokenInteractive(props) ? get('colors.shadow.medium') : undefined, props => isTokenInteractive(props) ? get('colors.fg.default') : undefined);
13
+ const TokenTextContainer = styled('span').withConfig({
14
+ displayName: "Token__TokenTextContainer",
15
+ componentId: "sc-1dg52pw-1"
16
+ })(["flex-grow:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"]);
17
+ const LeadingVisualContainer = styled('span').withConfig({
18
+ displayName: "Token__LeadingVisualContainer",
19
+ componentId: "sc-1dg52pw-2"
20
+ })(["flex-shrink:0;line-height:0;"]);
21
+ const Token = /*#__PURE__*/forwardRef((props, forwardedRef) => {
22
+ const {
23
+ as,
24
+ handleRemove,
25
+ id,
26
+ leadingVisual: LeadingVisual,
27
+ ref,
28
+ text,
29
+ variant,
30
+ hideRemoveButton,
31
+ ...rest
32
+ } = props;
33
+ const hasMultipleActionTargets = isTokenInteractive(props) && Boolean(handleRemove) && !hideRemoveButton;
34
+
35
+ const handleRemoveClick = e => {
36
+ e.stopPropagation();
37
+ handleRemove && handleRemove();
38
+ };
39
+
40
+ return /*#__PURE__*/React.createElement(DefaultTokenStyled, _extends({
41
+ as: as,
42
+ handleRemove: handleRemove,
43
+ hideRemoveButton: hideRemoveButton || !handleRemove,
44
+ id: id === null || id === void 0 ? void 0 : id.toString(),
45
+ text: text,
46
+ ref: forwardedRef,
47
+ variant: variant
48
+ }, rest), LeadingVisual ? /*#__PURE__*/React.createElement(LeadingVisualContainer, null, /*#__PURE__*/React.createElement(LeadingVisual, null)) : null, /*#__PURE__*/React.createElement(TokenTextContainer, null, text), !hideRemoveButton && handleRemove ? /*#__PURE__*/React.createElement(RemoveTokenButton, {
49
+ borderOffset: tokenBorderWidthPx,
50
+ parentTokenTag: as || 'span',
51
+ onClick: handleRemoveClick,
52
+ variant: variant,
53
+ parentTokenIsInteractive: isTokenInteractive(props),
54
+ "aria-hidden": hasMultipleActionTargets ? 'true' : 'false'
55
+ }) : null);
56
+ });
57
+ export default Token;
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ export declare type TokenSizeKeys = 'sm' | 'md' | 'lg' | 'xl';
3
+ export declare const tokenSizes: Record<TokenSizeKeys, number>;
4
+ export declare const defaultTokenSize = "md";
5
+ export interface TokenBaseProps extends Omit<React.HTMLProps<HTMLSpanElement | HTMLButtonElement | HTMLAnchorElement>, 'size' | 'id'> {
6
+ as?: 'button' | 'a' | 'span';
7
+ handleRemove?: () => void;
8
+ isSelected?: boolean;
9
+ tabIndex?: number;
10
+ text: string;
11
+ id?: number | string;
12
+ variant?: TokenSizeKeys;
13
+ }
14
+ export declare const isTokenInteractive: ({ as, onClick, onFocus, tabIndex }: TokenBaseProps) => boolean;
15
+ declare const TokenBase: import("styled-components").StyledComponent<"span", any, TokenBaseProps, never>;
16
+ export default TokenBase;
@@ -0,0 +1,70 @@
1
+ import styled from 'styled-components';
2
+ import { variant } from 'styled-system';
3
+ import { get } from '../constants';
4
+ export const tokenSizes = {
5
+ sm: 16,
6
+ md: 20,
7
+ lg: 24,
8
+ xl: 32
9
+ };
10
+ export const defaultTokenSize = 'md';
11
+ export const isTokenInteractive = ({
12
+ as = 'span',
13
+ onClick,
14
+ onFocus,
15
+ tabIndex = -1
16
+ }) => Boolean(onFocus || onClick || tabIndex > -1 || ['a', 'button'].includes(as));
17
+ const variants = variant({
18
+ variants: {
19
+ sm: {
20
+ fontSize: 0,
21
+ gap: 1,
22
+ height: `${tokenSizes.sm}px`,
23
+ paddingLeft: 1,
24
+ paddingRight: 1
25
+ },
26
+ md: {
27
+ fontSize: 0,
28
+ gap: 1,
29
+ height: `${tokenSizes.md}px`,
30
+ paddingLeft: 2,
31
+ paddingRight: 2
32
+ },
33
+ lg: {
34
+ fontSize: 0,
35
+ gap: 2,
36
+ height: `${tokenSizes.lg}px`,
37
+ paddingLeft: 2,
38
+ paddingRight: 2
39
+ },
40
+ xl: {
41
+ fontSize: 1,
42
+ gap: 2,
43
+ height: `${tokenSizes.xl}px`,
44
+ paddingLeft: 3,
45
+ paddingRight: 3
46
+ }
47
+ }
48
+ });
49
+ const TokenBase = styled.span.attrs(({
50
+ text,
51
+ handleRemove,
52
+ onKeyUp
53
+ }) => ({
54
+ onKeyUp: event => {
55
+ onKeyUp && onKeyUp(event);
56
+
57
+ if ((event.key === 'Backspace' || event.key === 'Delete') && handleRemove) {
58
+ handleRemove();
59
+ }
60
+ },
61
+ 'aria-label': handleRemove ? `${text}, press backspace or delete to remove` : undefined
62
+ })).withConfig({
63
+ displayName: "TokenBase",
64
+ componentId: "opajvp-0"
65
+ })(["align-items:center;border-radius:999px;cursor:", ";display:inline-flex;font-weight:", ";text-decoration:none;white-space:nowrap;", ""], props => isTokenInteractive(props) ? 'pointer' : 'auto', get('fontWeights.bold'), variants);
66
+ TokenBase.defaultProps = {
67
+ as: 'span',
68
+ variant: defaultTokenSize
69
+ };
70
+ export default TokenBase;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { TokenBaseProps } from './TokenBase';
3
+ export interface TokenLabelProps extends TokenBaseProps {
4
+ /**
5
+ * The color that corresponds to the label
6
+ */
7
+ fillColor?: string;
8
+ /**
9
+ * Whether the remove button should be rendered in the token
10
+ */
11
+ hideRemoveButton?: boolean;
12
+ }
13
+ declare const TokenLabel: React.ForwardRefExoticComponent<Pick<TokenLabelProps, "sizes" | "color" | "content" | "height" | "translate" | "width" | "hidden" | "children" | "value" | "cite" | "data" | "form" | "label" | "slot" | "span" | "style" | "summary" | "title" | "pattern" | "text" | "list" | "default" | "type" | "name" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "start" | "step" | "wrap" | "open" | "max" | "media" | "method" | "min" | "target" | "crossOrigin" | "href" | "classID" | "useMap" | "wmode" | "download" | "hrefLang" | "rel" | "alt" | "coords" | "shape" | "autoPlay" | "controls" | "loop" | "mediaGroup" | "muted" | "playsInline" | "preload" | "src" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "dateTime" | "acceptCharset" | "action" | "autoComplete" | "encType" | "noValidate" | "manifest" | "allowFullScreen" | "allowTransparency" | "frameBorder" | "marginHeight" | "marginWidth" | "sandbox" | "scrolling" | "seamless" | "srcDoc" | "srcSet" | "async" | "accept" | "capture" | "checked" | "maxLength" | "minLength" | "multiple" | "readOnly" | "required" | "challenge" | "keyType" | "keyParams" | "htmlFor" | "as" | "integrity" | "charSet" | "httpEquiv" | "high" | "low" | "optimum" | "reversed" | "selected" | "defer" | "nonce" | "scoped" | "cellPadding" | "cellSpacing" | "colSpan" | "headers" | "rowSpan" | "scope" | "cols" | "rows" | "kind" | "srcLang" | "poster" | "variant" | "handleRemove" | "isSelected" | "hideRemoveButton" | "fillColor"> & React.RefAttributes<HTMLElement>>;
14
+ export default TokenLabel;
@@ -0,0 +1,121 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React, { forwardRef } from 'react';
4
+ import styled, { css } from 'styled-components';
5
+ import TokenBase, { isTokenInteractive } from './TokenBase';
6
+ import RemoveTokenButton from './_RemoveTokenButton';
7
+ import tinycolor from 'tinycolor2';
8
+ import { useTheme } from '../ThemeProvider';
9
+ const colorModeConfigs = {
10
+ dark: {
11
+ bgOpacity: 0.18,
12
+ borderThreshold: 0,
13
+ borderOpacity: 0.3,
14
+ lightnessThreshold: 0.6
15
+ },
16
+ light: {
17
+ bgOpacity: 1,
18
+ borderThreshold: 0.96,
19
+ borderOpacity: 1,
20
+ lightnessThreshold: 0.453
21
+ }
22
+ };
23
+ const tokenBorderWidthPx = 1;
24
+ const StyledTokenLabel = styled(TokenBase).withConfig({
25
+ displayName: "TokenLabel__StyledTokenLabel",
26
+ componentId: "sc-1bdmgzv-0"
27
+ })(["background-color:", ";border-width:", "px;border-style:solid;border-color:", ";color:", ";padding-right:", ";position:relative;", ""], props => props.bgColor, tokenBorderWidthPx, props => props.borderColor, props => props.textColor, props => !props.hideRemoveButton ? 0 : undefined, props => {
28
+ if (props.isSelected) {
29
+ return css(["&:after{content:'';position:absolute;z-index:1;top:-2px;right:-2px;bottom:-2px;left:-2px;display:block;pointer-events:none;box-shadow:0 0 0 2px ", ";border-radius:999px;}"], props.bgColor);
30
+ }
31
+ });
32
+ const TokenTextContainer = styled('span').withConfig({
33
+ displayName: "TokenLabel__TokenTextContainer",
34
+ componentId: "sc-1bdmgzv-1"
35
+ })(["flex-grow:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"]);
36
+ const TokenLabel = /*#__PURE__*/forwardRef((props, forwardedRef) => {
37
+ const {
38
+ as,
39
+ fillColor,
40
+ handleRemove,
41
+ id,
42
+ isSelected,
43
+ ref,
44
+ text,
45
+ variant,
46
+ hideRemoveButton,
47
+ ...rest
48
+ } = props;
49
+ const {
50
+ colorScheme
51
+ } = useTheme();
52
+ const {
53
+ bgOpacity,
54
+ borderOpacity,
55
+ borderThreshold,
56
+ lightnessThreshold
57
+ } = colorModeConfigs[colorScheme || 'light'];
58
+ let bgColor = fillColor;
59
+ let borderColor = fillColor;
60
+ let textColor = '#FFF';
61
+ const perceivedLightness = tinycolor(fillColor).getLuminance();
62
+ const isFillColorLight = perceivedLightness >= lightnessThreshold;
63
+
64
+ if (colorScheme === 'dark') {
65
+ const lightenBy = (perceivedLightness - lightnessThreshold) * 100 * (isFillColorLight ? 1 : 0);
66
+ bgColor = isSelected ? tinycolor(fillColor).setAlpha(bgOpacity * 1.2).toRgbString() : tinycolor(fillColor).setAlpha(bgOpacity).toRgbString();
67
+ textColor = isSelected ? tinycolor(fillColor).lighten(lightenBy + 10).toString() : tinycolor(fillColor).lighten(lightenBy).toString();
68
+ borderColor = isSelected ? tinycolor(fillColor).lighten(lightenBy + 5).toRgbString() : tinycolor(fillColor).lighten(lightenBy).setAlpha(borderOpacity).toRgbString();
69
+ } else {
70
+ const isFillColorDark = perceivedLightness < 0.1;
71
+ borderColor = perceivedLightness >= borderThreshold ? tinycolor(fillColor).darken(25).toString() : 'transparent';
72
+
73
+ if (isFillColorLight) {
74
+ textColor = '#000';
75
+ }
76
+
77
+ if (isSelected) {
78
+ bgColor = isFillColorDark ? tinycolor(fillColor).lighten(10).toString() : // TODO: darken more than 10 if the fillColor is really bright and doesn't darken well
79
+ // Examples of colors that don't darken well:
80
+ // - #a2eeef
81
+ // - #ffd78e
82
+ // - #a4f287
83
+ tinycolor(fillColor).darken(10).toString();
84
+ }
85
+ }
86
+
87
+ const hasMultipleActionTargets = isTokenInteractive(props) && Boolean(handleRemove) && !hideRemoveButton;
88
+
89
+ const handleRemoveClick = e => {
90
+ e.stopPropagation();
91
+ handleRemove && handleRemove();
92
+ };
93
+
94
+ return /*#__PURE__*/React.createElement(StyledTokenLabel // specific to labels
95
+ , _extends({
96
+ fillColor: fillColor,
97
+ bgColor: bgColor,
98
+ borderColor: borderColor,
99
+ textColor: textColor // common token props
100
+ ,
101
+ as: as,
102
+ hideRemoveButton: hideRemoveButton || !handleRemove,
103
+ handleRemove: handleRemove,
104
+ id: id === null || id === void 0 ? void 0 : id.toString(),
105
+ isSelected: isSelected,
106
+ ref: forwardedRef,
107
+ text: text,
108
+ variant: variant
109
+ }, rest), /*#__PURE__*/React.createElement(TokenTextContainer, null, text), !hideRemoveButton && handleRemove ? /*#__PURE__*/React.createElement(RemoveTokenButton, {
110
+ borderOffset: tokenBorderWidthPx,
111
+ parentTokenTag: as || 'span',
112
+ tabIndex: -1,
113
+ onClick: handleRemoveClick,
114
+ variant: variant,
115
+ "aria-hidden": hasMultipleActionTargets ? 'true' : 'false'
116
+ }) : null);
117
+ });
118
+ TokenLabel.defaultProps = {
119
+ fillColor: '#999'
120
+ };
121
+ export default TokenLabel;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { TokenBaseProps } from './TokenBase';
3
+ export interface TokenProfileProps extends TokenBaseProps {
4
+ avatarSrc: string;
5
+ }
6
+ declare const TokenProfile: React.ForwardRefExoticComponent<Pick<TokenProfileProps, "sizes" | "color" | "content" | "height" | "translate" | "width" | "hidden" | "children" | "value" | "cite" | "data" | "form" | "label" | "slot" | "span" | "style" | "summary" | "title" | "pattern" | "text" | "list" | "default" | "type" | "name" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "start" | "step" | "wrap" | "open" | "max" | "media" | "method" | "min" | "target" | "crossOrigin" | "href" | "classID" | "useMap" | "wmode" | "download" | "hrefLang" | "rel" | "alt" | "coords" | "shape" | "autoPlay" | "controls" | "loop" | "mediaGroup" | "muted" | "playsInline" | "preload" | "src" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "dateTime" | "acceptCharset" | "action" | "autoComplete" | "encType" | "noValidate" | "manifest" | "allowFullScreen" | "allowTransparency" | "frameBorder" | "marginHeight" | "marginWidth" | "sandbox" | "scrolling" | "seamless" | "srcDoc" | "srcSet" | "async" | "accept" | "capture" | "checked" | "maxLength" | "minLength" | "multiple" | "readOnly" | "required" | "challenge" | "keyType" | "keyParams" | "htmlFor" | "as" | "integrity" | "charSet" | "httpEquiv" | "high" | "low" | "optimum" | "reversed" | "selected" | "defer" | "nonce" | "scoped" | "cellPadding" | "cellSpacing" | "colSpan" | "headers" | "rowSpan" | "scope" | "cols" | "rows" | "kind" | "srcLang" | "poster" | "variant" | "handleRemove" | "isSelected" | "avatarSrc"> & React.RefAttributes<HTMLElement>>;
7
+ export default TokenProfile;
@@ -0,0 +1,29 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React, { forwardRef } from 'react';
4
+ import styled from 'styled-components';
5
+ import { get } from '../constants';
6
+ import primitives from '@primer/primitives';
7
+ import { defaultTokenSize, tokenSizes } from './TokenBase';
8
+ import Token from './Token';
9
+ import { Avatar } from '..';
10
+ const StyledToken = styled(Token).withConfig({
11
+ displayName: "TokenProfile__StyledToken",
12
+ componentId: "sc-1vf9jhf-0"
13
+ })(["padding-left:", ";"], get('space.1'));
14
+ const TokenProfile = /*#__PURE__*/forwardRef(({
15
+ avatarSrc,
16
+ id,
17
+ ref,
18
+ variant,
19
+ ...rest
20
+ }, forwardedRef) => /*#__PURE__*/React.createElement(StyledToken, _extends({
21
+ leadingVisual: () => /*#__PURE__*/React.createElement(Avatar, {
22
+ src: avatarSrc,
23
+ size: tokenSizes[variant || defaultTokenSize] - parseInt(primitives.spacing.normal.spacer[1], 10) * 2
24
+ }),
25
+ variant: variant,
26
+ id: id === null || id === void 0 ? void 0 : id.toString(),
27
+ ref: forwardedRef
28
+ }, rest)));
29
+ export default TokenProfile;
@@ -0,0 +1,3 @@
1
+ import { TokenButtonProps } from './_tokenButtonUtils';
2
+ declare const RemoveTokenButton: import("styled-components").StyledComponent<"span", any, TokenButtonProps, never>;
3
+ export default RemoveTokenButton;
@@ -0,0 +1,29 @@
1
+ import { XIcon } from '@primer/octicons-react';
2
+ import styled from 'styled-components';
3
+ import { defaultTokenSize } from './TokenBase';
4
+ import { tokenButtonStyles, variants, getTokenButtonIconSize } from './_tokenButtonUtils';
5
+ const RemoveTokenButton = styled.span.attrs(({
6
+ borderOffset,
7
+ parentTokenTag,
8
+ variant,
9
+ parentTokenIsInteractive,
10
+ ...rest
11
+ }) => {
12
+ delete rest.children;
13
+ return {
14
+ borderOffset,
15
+ as: parentTokenIsInteractive ? 'span' : 'button',
16
+ tabIndex: parentTokenIsInteractive ? -1 : undefined,
17
+ 'aria-label': !parentTokenIsInteractive ? 'Remove token' : undefined,
18
+ children: /*#__PURE__*/React.createElement(XIcon, {
19
+ size: getTokenButtonIconSize(variant)
20
+ })
21
+ };
22
+ }).withConfig({
23
+ displayName: "_RemoveTokenButton__RemoveTokenButton",
24
+ componentId: "sc-14lvcw1-0"
25
+ })(["", " ", " transform:", ";"], tokenButtonStyles, variants, props => `translate(${props.borderOffset}px, -${props.borderOffset}px)`);
26
+ RemoveTokenButton.defaultProps = {
27
+ variant: defaultTokenSize
28
+ };
29
+ export default RemoveTokenButton;
@@ -0,0 +1,10 @@
1
+ import { TokenSizeKeys } from './TokenBase';
2
+ export interface TokenButtonProps {
3
+ borderOffset?: number;
4
+ parentTokenTag: 'span' | 'button' | 'a';
5
+ variant?: TokenSizeKeys;
6
+ parentTokenIsInteractive?: boolean;
7
+ }
8
+ export declare const variants: (...args: any[]) => any;
9
+ export declare const tokenButtonStyles: import("styled-components").FlattenInterpolation<import("styled-components").ThemeProps<any>>;
10
+ export declare const getTokenButtonIconSize: (variant?: TokenSizeKeys | undefined) => number;
@@ -0,0 +1,26 @@
1
+ import { css } from 'styled-components';
2
+ import { variant } from 'styled-system';
3
+ import { get } from '../constants';
4
+ import { tokenSizes, defaultTokenSize } from './TokenBase';
5
+ export const variants = variant({
6
+ variants: {
7
+ sm: {
8
+ height: `${tokenSizes.sm}px`,
9
+ width: `${tokenSizes.sm}px`
10
+ },
11
+ md: {
12
+ height: `${tokenSizes.md}px`,
13
+ width: `${tokenSizes.md}px`
14
+ },
15
+ lg: {
16
+ height: `${tokenSizes.lg}px`,
17
+ width: `${tokenSizes.lg}px`
18
+ },
19
+ xl: {
20
+ height: `${tokenSizes.xl}px`,
21
+ width: `${tokenSizes.xl}px`
22
+ }
23
+ }
24
+ });
25
+ export const tokenButtonStyles = css(["background-color:transparent;font-family:inherit;color:currentColor;cursor:pointer;display:inline-flex;justify-content:center;align-items:center;user-select:none;appearance:none;text-decoration:none;padding:0;align-self:baseline;border:0;border-radius:999px;&:hover,&:focus{background-color:", ";}&:active{background-color:", ";}"], get('colors.fade.fg10'), get('colors.fade.fg15'));
26
+ export const getTokenButtonIconSize = variant => tokenSizes[variant || defaultTokenSize] * 0.75;
@@ -0,0 +1,3 @@
1
+ export { default } from './Token';
2
+ export { default as TokenLabel } from './TokenLabel';
3
+ export { default as TokenProfile } from './TokenProfile';
@@ -0,0 +1,3 @@
1
+ export { default } from './Token';
2
+ export { default as TokenLabel } from './TokenLabel';
3
+ export { default as TokenProfile } from './TokenProfile';
@@ -102,6 +102,7 @@ export { default as Text } from './Text';
102
102
  export type { TextProps } from './Text';
103
103
  export { default as Timeline } from './Timeline';
104
104
  export type { TimelineProps, TimelineBadgeProps, TimelineBodyProps, TimelineBreakProps, TimelineItemsProps } from './Timeline';
105
+ export { default as Token, TokenLabel, TokenProfile } from './Token';
105
106
  export { default as Tooltip } from './Tooltip';
106
107
  export type { TooltipProps } from './Tooltip';
107
108
  export { default as Truncate } from './Truncate';
package/lib-esm/index.js CHANGED
@@ -63,6 +63,7 @@ export { default as TabNav } from './TabNav';
63
63
  export { default as TextInput } from './TextInput';
64
64
  export { default as Text } from './Text';
65
65
  export { default as Timeline } from './Timeline';
66
+ export { default as Token, TokenLabel, TokenProfile } from './Token';
66
67
  export { default as Tooltip } from './Tooltip';
67
68
  export { default as Truncate } from './Truncate';
68
69
  export { default as UnderlineNav } from './UnderlineNav';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-20219416616",
3
+ "version": "0.0.0-20219421241",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -58,7 +58,8 @@
58
58
  "classnames": "2.3.1",
59
59
  "deepmerge": "4.2.2",
60
60
  "focus-visible": "5.2.0",
61
- "styled-system": "5.1.5"
61
+ "styled-system": "5.1.5",
62
+ "tinycolor2": "1.4.2"
62
63
  },
63
64
  "devDependencies": {
64
65
  "@babel/cli": "7.14.5",
@@ -90,6 +91,7 @@
90
91
  "@types/jest-axe": "3.5.3",
91
92
  "@types/lodash.isempty": "4.4.6",
92
93
  "@types/lodash.isobject": "3.0.6",
94
+ "@types/tinycolor2": "1.4.3",
93
95
  "@typescript-eslint/eslint-plugin": "4.31.2",
94
96
  "@typescript-eslint/parser": "4.26.1",
95
97
  "@wojtekmaj/enzyme-adapter-react-17": "0.6.3",