@norges-domstoler/dds-components 13.0.2 → 13.1.0

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 (31) hide show
  1. package/dist/cjs/components/DescriptionList/DescriptionList.tokens.d.ts +0 -6
  2. package/dist/cjs/components/InlineEdit/InlineEdit.styles.d.ts +6 -0
  3. package/dist/cjs/components/TextArea/TextArea.d.ts +3 -0
  4. package/dist/cjs/components/TextInput/TextInput.d.ts +2 -0
  5. package/dist/cjs/components/TextInput/TextInput.stories.d.ts +3 -0
  6. package/dist/cjs/components/TextInput/TextInput.styles.d.ts +3 -0
  7. package/dist/cjs/components/TextInput/TextInput.tokens.d.ts +5 -0
  8. package/dist/cjs/components/TextInput/TextInput.types.d.ts +7 -0
  9. package/dist/cjs/helpers/Input/Input.styles.d.ts +4 -0
  10. package/dist/cjs/helpers/Input/Input.tokens.d.ts +3 -0
  11. package/dist/cjs/helpers/Input/Input.types.d.ts +4 -1
  12. package/dist/cjs/index.js +99 -23
  13. package/dist/components/DescriptionList/DescriptionList.js +2 -3
  14. package/dist/components/DescriptionList/DescriptionList.tokens.d.ts +0 -6
  15. package/dist/components/DescriptionList/DescriptionList.tokens.js +1 -6
  16. package/dist/components/DescriptionList/DescriptionListDesc.js +2 -3
  17. package/dist/components/InlineEdit/InlineEdit.styles.d.ts +6 -0
  18. package/dist/components/TextArea/TextArea.d.ts +3 -0
  19. package/dist/components/TextInput/TextInput.d.ts +2 -0
  20. package/dist/components/TextInput/TextInput.js +75 -11
  21. package/dist/components/TextInput/TextInput.stories.d.ts +3 -0
  22. package/dist/components/TextInput/TextInput.styles.d.ts +3 -0
  23. package/dist/components/TextInput/TextInput.tokens.d.ts +5 -0
  24. package/dist/components/TextInput/TextInput.tokens.js +7 -1
  25. package/dist/components/TextInput/TextInput.types.d.ts +7 -0
  26. package/dist/helpers/Input/Input.styles.d.ts +4 -0
  27. package/dist/helpers/Input/Input.styles.js +17 -7
  28. package/dist/helpers/Input/Input.tokens.d.ts +3 -0
  29. package/dist/helpers/Input/Input.tokens.js +3 -0
  30. package/dist/helpers/Input/Input.types.d.ts +4 -1
  31. package/package.json +1 -1
@@ -1,9 +1,3 @@
1
- import { StaticTypographyType } from '../Typography';
2
- import { DescriptionListAppearance } from './DescriptionList';
3
- export declare const termTypographyTypes: {
4
- [k in DescriptionListAppearance]: StaticTypographyType;
5
- };
6
- export declare const descTypographyType: StaticTypographyType;
7
1
  export declare const descriptionListTokens: {
8
2
  term: {
9
3
  appearance: {
@@ -6,9 +6,15 @@ type StyledInlineInputProps = {
6
6
  };
7
7
  export declare const StyledInlineInput: import("styled-components").StyledComponent<"input", any, Pick<import("../../helpers").InputProps, "disabled" | "readOnly"> & {
8
8
  hasErrorMessage: boolean;
9
+ } & {
10
+ prefixLength?: number | undefined;
11
+ suffixLength?: number | undefined;
9
12
  } & Pick<import("../../helpers").InputProps, "componentSize"> & StyledInlineInputProps, never>;
10
13
  export declare const StyledInlineTextArea: import("styled-components").StyledComponent<"input", any, Pick<import("../../helpers").InputProps, "disabled" | "readOnly"> & {
11
14
  hasErrorMessage: boolean;
15
+ } & {
16
+ prefixLength?: number | undefined;
17
+ suffixLength?: number | undefined;
12
18
  } & Pick<import("../../helpers").InputProps, "componentSize"> & StyledInlineInputProps, never>;
13
19
  export declare const IconWrapper: import("styled-components").StyledComponent<"span", any, {}, never>;
14
20
  export {};
@@ -2,6 +2,9 @@ import { TextareaHTMLAttributes } from 'react';
2
2
  import { CommonInputProps } from '../../helpers/Input';
3
3
  export declare const StyledTextArea: import("styled-components").StyledComponent<"input", any, Pick<import("../../helpers/Input").InputProps, "disabled" | "readOnly"> & {
4
4
  hasErrorMessage: boolean;
5
+ } & {
6
+ prefixLength?: number | undefined;
7
+ suffixLength?: number | undefined;
5
8
  } & Pick<import("../../helpers/Input").InputProps, "componentSize">, never>;
6
9
  export type TextAreaProps = CommonInputProps & TextareaHTMLAttributes<HTMLTextAreaElement>;
7
10
  export declare const TextArea: import("react").ForwardRefExoticComponent<CommonInputProps & TextareaHTMLAttributes<HTMLTextAreaElement> & import("react").RefAttributes<HTMLTextAreaElement>>;
@@ -5,4 +5,6 @@ export declare const TextInput: React.ForwardRefExoticComponent<import("../../he
5
5
  } & React.InputHTMLAttributes<HTMLInputElement> & {
6
6
  withCharacterCounter?: boolean | undefined;
7
7
  icon?: import("../../icons/utils").SvgIcon | undefined;
8
+ prefix?: string | undefined;
9
+ suffix?: string | undefined;
8
10
  } & React.RefAttributes<HTMLInputElement>>;
@@ -6,6 +6,8 @@ declare const _default: {
6
6
  } & import("react").InputHTMLAttributes<HTMLInputElement> & {
7
7
  withCharacterCounter?: boolean | undefined;
8
8
  icon?: import("../../icons/utils").SvgIcon | undefined;
9
+ prefix?: string | undefined;
10
+ suffix?: string | undefined;
9
11
  } & import("react").RefAttributes<HTMLInputElement>>;
10
12
  argTypes: {
11
13
  label: {
@@ -56,3 +58,4 @@ export declare const TextInputOverviewSizes: () => JSX.Element;
56
58
  export declare const Default: (args: TextInputProps) => JSX.Element;
57
59
  export declare const WithLabel: (args: TextInputProps) => JSX.Element;
58
60
  export declare const WithCharacterCount: (args: TextInputProps) => JSX.Element;
61
+ export declare const TextInputAffixes: (args: TextInputProps) => JSX.Element;
@@ -10,5 +10,8 @@ type StyledInputProps = {
10
10
  };
11
11
  export declare const StyledInput: import("styled-components").StyledComponent<"input", any, Pick<import("../../helpers").InputProps, "disabled" | "readOnly"> & {
12
12
  hasErrorMessage: boolean;
13
+ } & {
14
+ prefixLength?: number | undefined;
15
+ suffixLength?: number | undefined;
13
16
  } & Pick<import("../../helpers").InputProps, "componentSize"> & StyledInputProps, never>;
14
17
  export {};
@@ -29,4 +29,9 @@ export declare const textInputTokens: {
29
29
  };
30
30
  };
31
31
  };
32
+ affix: {
33
+ border: {
34
+ color: string;
35
+ };
36
+ };
32
37
  };
@@ -5,4 +5,11 @@ export type TextInputProps = InputProps & {
5
5
  withCharacterCounter?: boolean;
6
6
  /** Ikonet som vises i komponenten. */
7
7
  icon?: SvgIcon;
8
+ /** Prefiks som vises før inputfeltet. */
9
+ prefix?: string;
10
+ /** Suffiks som vises etter inputfeltet. */
11
+ suffix?: string;
12
+ };
13
+ export type TextAffixProps = {
14
+ readOnly?: boolean;
8
15
  };
@@ -2,6 +2,9 @@ import { Property } from 'csstype';
2
2
  export declare const Input: import("styled-components").StyledComponent<"input", any, {}, never>;
3
3
  export declare const StatefulInput: import("styled-components").StyledComponent<"input", any, Pick<import("./Input.types").InputProps, "disabled" | "readOnly"> & {
4
4
  hasErrorMessage: boolean;
5
+ } & {
6
+ prefixLength?: number | undefined;
7
+ suffixLength?: number | undefined;
5
8
  } & Pick<import("./Input.types").InputProps, "componentSize">, never>;
6
9
  type OuterInputContainerProps = {
7
10
  width?: Property.Width;
@@ -9,4 +12,5 @@ type OuterInputContainerProps = {
9
12
  export declare const OuterInputContainer: import("styled-components").StyledComponent<"div", any, OuterInputContainerProps, never>;
10
13
  /**Brukes som container til input og ikon for posisjonering. */
11
14
  export declare const InputContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
15
+ export declare const InputAffixContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
12
16
  export {};
@@ -28,6 +28,9 @@ export declare const inputTokens: {
28
28
  padding: string;
29
29
  };
30
30
  };
31
+ affix: {
32
+ gap: number;
33
+ };
31
34
  };
32
35
  container: {
33
36
  gap: string;
@@ -19,7 +19,10 @@ export type InputProps = CommonInputProps & {
19
19
  export type StyledCommonInputProps = Pick<InputProps, 'readOnly' | 'disabled'> & {
20
20
  hasErrorMessage: boolean;
21
21
  };
22
- export type StyledInputProps = StyledCommonInputProps & Pick<InputProps, 'componentSize'>;
22
+ export type StyledInputProps = StyledCommonInputProps & {
23
+ prefixLength?: number;
24
+ suffixLength?: number;
25
+ } & Pick<InputProps, 'componentSize'>;
23
26
  export type InputTypographyTypes = {
24
27
  [k in InputSize]: StaticTypographyType;
25
28
  };
package/dist/cjs/index.js CHANGED
@@ -813,6 +813,9 @@ var input$5 = {
813
813
  tiny: {
814
814
  padding: "".concat(spacing$B.SizesDdsSpacingLocalX025, " ").concat(spacing$B.SizesDdsSpacingLocalX05, " ").concat(spacing$B.SizesDdsSpacingLocalX025, " ").concat(spacing$B.SizesDdsSpacingLocalX05)
815
815
  }
816
+ },
817
+ affix: {
818
+ gap: spacing$B.SizesDdsSpacingLocalX1NumberPx
816
819
  }
817
820
  };
818
821
  var container$g = {
@@ -832,18 +835,24 @@ var Input$2 = styled__default.default.input.withConfig({
832
835
  var StatefulInput = styled__default.default(Input$2).withConfig({
833
836
  displayName: "Inputstyles__StatefulInput",
834
837
  componentId: "sc-1oz9x8w-1"
835
- })(["-webkit-appearance:textfield;", " ", " &:enabled:read-only{border:none;outline:none;cursor:default;background-color:", ";padding-left:0;}&:disabled{cursor:not-allowed;color:", ";background-color:", ";}"], function (_ref) {
836
- var componentSize = _ref.componentSize;
837
- return componentSize && styled.css(["padding:", ";", ""], input$4.sizes[componentSize].padding, getFontStyling(inputTypographyTypes[componentSize]));
838
+ })(["-webkit-appearance:textfield;padding-left:", ";padding-right:", ";", " ", " &:enabled:read-only{border:none;outline:none;cursor:default;background-color:", ";padding-left:0;}&:disabled{cursor:not-allowed;color:", ";background-color:", ";}"], function (_ref) {
839
+ var prefixLength = _ref.prefixLength;
840
+ return prefixLength && "calc(".concat(input$4.affix.gap, "px + ").concat(prefixLength, "px) !important");
838
841
  }, function (_ref2) {
839
- var hasErrorMessage = _ref2.hasErrorMessage;
842
+ var suffixLength = _ref2.suffixLength;
843
+ return suffixLength && "calc(".concat(input$4.affix.gap, "px + ").concat(suffixLength, "px) !important");
844
+ }, function (_ref3) {
845
+ var componentSize = _ref3.componentSize;
846
+ return componentSize && styled.css(["padding:", ";", ""], input$4.sizes[componentSize].padding, getFontStyling(inputTypographyTypes[componentSize]));
847
+ }, function (_ref4) {
848
+ var hasErrorMessage = _ref4.hasErrorMessage;
840
849
  return hasErrorMessage && styled.css(["", " &:hover:enabled:read-write{", "}&:focus:enabled:read-write,&:active:enabled:read-write{", "}"], dangerInputfield, hoverDangerInputfield, focusDangerInputfield);
841
850
  }, input$4.readOnly.backgroundColor, input$4.disabled.color, input$4.disabled.backgroundColor);
842
851
  var OuterInputContainer = styled__default.default.div.withConfig({
843
852
  displayName: "Inputstyles__OuterInputContainer",
844
853
  componentId: "sc-1oz9x8w-2"
845
- })(["position:relative;gap:", ";width:", ";"], container$f.gap, function (_ref3) {
846
- var width = _ref3.width;
854
+ })(["position:relative;gap:", ";width:", ";"], container$f.gap, function (_ref5) {
855
+ var width = _ref5.width;
847
856
  return width;
848
857
  });
849
858
  /**Brukes som container til input og ikon for posisjonering. */
@@ -851,6 +860,10 @@ var InputContainer$1 = styled__default.default.div.withConfig({
851
860
  displayName: "Inputstyles__InputContainer",
852
861
  componentId: "sc-1oz9x8w-3"
853
862
  })(["position:relative;"]);
863
+ var InputAffixContainer = styled__default.default.div.withConfig({
864
+ displayName: "Inputstyles__InputAffixContainer",
865
+ componentId: "sc-1oz9x8w-4"
866
+ })(["position:relative;display:flex;align-items:center;"]);
854
867
 
855
868
  var getSize = function getSize(iconSize) {
856
869
  switch (iconSize) {
@@ -4254,6 +4267,11 @@ var input$3 = {
4254
4267
  }
4255
4268
  }
4256
4269
  };
4270
+ var affix = {
4271
+ border: {
4272
+ color: colors$o.DdsColorNeutralsGray5
4273
+ }
4274
+ };
4257
4275
  var icon$9 = {
4258
4276
  color: colors$o.DdsColorNeutralsGray9,
4259
4277
  sizes: {
@@ -4273,7 +4291,8 @@ var icon$9 = {
4273
4291
  };
4274
4292
  var textInputTokens = {
4275
4293
  input: input$3,
4276
- icon: icon$9
4294
+ icon: icon$9,
4295
+ affix: affix
4277
4296
  };
4278
4297
 
4279
4298
  var iconSizes$4 = ddsDesignTokens.ddsBaseTokens.iconSizes;
@@ -4309,6 +4328,20 @@ var getWidth$1 = function getWidth(size, width) {
4309
4328
  }
4310
4329
  return defaultWidth$5;
4311
4330
  };
4331
+ var Prefix = styled__default.default.span.withConfig({
4332
+ displayName: "TextInput__Prefix",
4333
+ componentId: "sc-k8umq3-0"
4334
+ })(["position:absolute;height:100%;top:50%;transform:translateY(-50%);display:flex;align-items:center;pointer-events:none;z-index:1;margin-left:8px;padding-right:8px;border-right:", ";"], function (_ref) {
4335
+ var readOnly = _ref.readOnly;
4336
+ return !readOnly && "1px solid ".concat(textInputTokens.affix.border.color);
4337
+ });
4338
+ var Suffix = styled__default.default.span.withConfig({
4339
+ displayName: "TextInput__Suffix",
4340
+ componentId: "sc-k8umq3-1"
4341
+ })(["position:absolute;height:100%;top:50%;right:0;transform:translateY(-50%);display:flex;align-items:center;pointer-events:none;z-index:1;margin-right:8px;padding-left:8px;border-left:", ";"], function (_ref2) {
4342
+ var readOnly = _ref2.readOnly;
4343
+ return !readOnly && "1px solid ".concat(textInputTokens.affix.border.color);
4344
+ });
4312
4345
  var TextInput = /*#__PURE__*/React.forwardRef(function (_a, ref) {
4313
4346
  var label = _a.label,
4314
4347
  disabled = _a.disabled,
@@ -4333,11 +4366,23 @@ var TextInput = /*#__PURE__*/React.forwardRef(function (_a, ref) {
4333
4366
  ariaRequired = _a['aria-required'],
4334
4367
  ariaDescribedby = _a['aria-describedby'],
4335
4368
  icon = _a.icon,
4336
- rest = tslib.__rest(_a, ["label", "disabled", "readOnly", "errorMessage", "tip", "required", "maxLength", "onChange", "id", "width", "componentSize", "type", "withCharacterCounter", "className", "style", "value", "defaultValue", 'aria-required', 'aria-describedby', "icon"]);
4369
+ prefix = _a.prefix,
4370
+ suffix = _a.suffix,
4371
+ rest = tslib.__rest(_a, ["label", "disabled", "readOnly", "errorMessage", "tip", "required", "maxLength", "onChange", "id", "width", "componentSize", "type", "withCharacterCounter", "className", "style", "value", "defaultValue", 'aria-required', 'aria-describedby', "icon", "prefix", "suffix"]);
4337
4372
  var _useState = React.useState(getDefaultText(value, defaultValue)),
4338
4373
  _useState2 = _slicedToArray(_useState, 2),
4339
4374
  text = _useState2[0],
4340
4375
  setText = _useState2[1];
4376
+ var prefixRef = React.useRef(null);
4377
+ var suffixRef = React.useRef(null);
4378
+ var _useState3 = React.useState(0),
4379
+ _useState4 = _slicedToArray(_useState3, 2),
4380
+ prefixLength = _useState4[0],
4381
+ setPrefixLength = _useState4[1];
4382
+ var _useState5 = React.useState(0),
4383
+ _useState6 = _slicedToArray(_useState5, 2),
4384
+ suffixLength = _useState6[0],
4385
+ setSuffixLength = _useState6[1];
4341
4386
  var onChangeHandler = function onChangeHandler(event) {
4342
4387
  setText(event.target.value);
4343
4388
  if (onChange) {
@@ -4351,6 +4396,7 @@ var TextInput = /*#__PURE__*/React.forwardRef(function (_a, ref) {
4351
4396
  var hasLabel = !!label;
4352
4397
  var hasMessage = hasErrorMessage || hasTip || !!maxLength;
4353
4398
  var hasIcon = !!icon;
4399
+ var hasAffix = !!(prefix || suffix);
4354
4400
  var characterCounterId = derivativeIdGenerator(uniqueId, 'characterCounter');
4355
4401
  var tipId = derivativeIdGenerator(uniqueId, 'tip');
4356
4402
  var errorMessageId = derivativeIdGenerator(uniqueId, 'errorMessage');
@@ -4375,13 +4421,17 @@ var TextInput = /*#__PURE__*/React.forwardRef(function (_a, ref) {
4375
4421
  width: getWidth$1(componentSize, width)
4376
4422
  };
4377
4423
  var showRequiredStyling = !!(required || ariaRequired);
4378
- return jsxRuntime.jsxs(OuterInputContainer, Object.assign({}, outerInputContainerProps, {
4379
- children: [hasLabel && jsxRuntime.jsx(Label$2, Object.assign({
4380
- htmlFor: uniqueId,
4381
- showRequiredStyling: showRequiredStyling
4382
- }, {
4383
- children: label
4384
- })), hasIcon ? jsxRuntime.jsxs(InputContainer$1, {
4424
+ React.useLayoutEffect(function () {
4425
+ if (prefixRef.current) {
4426
+ setPrefixLength(prefixRef.current.offsetWidth);
4427
+ }
4428
+ if (suffixRef.current) {
4429
+ setSuffixLength(suffixRef.current.offsetWidth);
4430
+ }
4431
+ }, []);
4432
+ var extendedInput = null;
4433
+ if (hasIcon) {
4434
+ extendedInput = jsxRuntime.jsxs(InputContainer$1, {
4385
4435
  children: [jsxRuntime.jsx(StyledIcon$3, {
4386
4436
  icon: icon,
4387
4437
  iconSize: getFormInputIconSize(componentSize),
@@ -4393,7 +4443,38 @@ var TextInput = /*#__PURE__*/React.forwardRef(function (_a, ref) {
4393
4443
  componentSize: componentSize,
4394
4444
  hasIcon: hasIcon
4395
4445
  }, generalInputProps))]
4396
- }) : jsxRuntime.jsx(StatefulInput, Object.assign({
4446
+ });
4447
+ } else if (hasAffix) {
4448
+ extendedInput = jsxRuntime.jsxs(InputAffixContainer, {
4449
+ children: [prefix && jsxRuntime.jsx(Prefix, Object.assign({
4450
+ readOnly: readOnly,
4451
+ ref: prefixRef,
4452
+ "aria-hidden": true
4453
+ }, {
4454
+ children: prefix
4455
+ })), jsxRuntime.jsx(StatefulInput, Object.assign({
4456
+ ref: ref,
4457
+ onChange: onChangeHandler,
4458
+ type: type,
4459
+ componentSize: componentSize,
4460
+ prefixLength: prefixLength,
4461
+ suffixLength: suffixLength
4462
+ }, generalInputProps)), suffix && jsxRuntime.jsx(Suffix, Object.assign({
4463
+ readOnly: readOnly,
4464
+ ref: suffixRef,
4465
+ "aria-hidden": true
4466
+ }, {
4467
+ children: suffix
4468
+ }))]
4469
+ });
4470
+ }
4471
+ return jsxRuntime.jsxs(OuterInputContainer, Object.assign({}, outerInputContainerProps, {
4472
+ children: [hasLabel && jsxRuntime.jsx(Label$2, Object.assign({
4473
+ htmlFor: uniqueId,
4474
+ showRequiredStyling: showRequiredStyling
4475
+ }, {
4476
+ children: label
4477
+ })), extendedInput ? extendedInput : jsxRuntime.jsx(StatefulInput, Object.assign({
4397
4478
  ref: ref,
4398
4479
  onChange: onChangeHandler,
4399
4480
  type: type,
@@ -6424,11 +6505,6 @@ var Row = /*#__PURE__*/React.forwardRef(function (_a, ref) {
6424
6505
 
6425
6506
  var spacing$p = ddsDesignTokens.ddsBaseTokens.spacing,
6426
6507
  colors$g = ddsDesignTokens.ddsBaseTokens.colors;
6427
- var termTypographyTypes = {
6428
- bold: 'bodySans03',
6429
- small: 'bodySans01'
6430
- };
6431
- var descTypographyType = 'bodySans03';
6432
6508
  var term$1 = {
6433
6509
  appearance: {
6434
6510
  small: {
@@ -6479,7 +6555,7 @@ var DList = styled__default.default.dl.withConfig({
6479
6555
  componentId: "sc-1ob73hm-0"
6480
6556
  })(["margin:0;*::selection{", "}", " display:flex;flex-direction:column;&:not(:has(> dt):has(> dd)){flex-direction:", ";}flex-wrap:wrap;column-gap:", ";row-gap:0;& > dt:first-of-type{margin-top:", ";}& > dd:last-child{margin-bottom:", ";}dd + dt{margin-top:", ";}"], selection, function (_ref) {
6481
6557
  var appearance = _ref.appearance;
6482
- return appearance && styled.css(["dt{color:", ";", " ", "}"], term.appearance[appearance].color, getFontStyling(termTypographyTypes[appearance]), appearance === 'bold' && styled.css(["font-weight:600;"]));
6558
+ return appearance && styled.css(["dt{color:", ";", "}"], term.appearance[appearance].color, appearance === 'bold' && styled.css(["font-weight:600;"]));
6483
6559
  }, function (_ref2) {
6484
6560
  var _ref2$direction = _ref2.direction,
6485
6561
  direction = _ref2$direction === void 0 ? 'column' : _ref2$direction;
@@ -6523,7 +6599,7 @@ var DescriptionListTerm = /*#__PURE__*/React.forwardRef(function (_a, ref) {
6523
6599
  var DListDesc = styled__default.default.dd.withConfig({
6524
6600
  displayName: "DescriptionListDesc__DListDesc",
6525
6601
  componentId: "sc-1djcf0s-0"
6526
- })(["margin-inline-start:0;align-items:center;display:flex;color:", ";", " gap:", ";"], descriptionListTokens.desc.base.color, getFontStyling(descTypographyType), descriptionListTokens.desc.base.gap);
6602
+ })(["margin-inline-start:0;align-items:center;display:flex;color:", ";gap:", ";"], descriptionListTokens.desc.base.color, descriptionListTokens.desc.base.gap);
6527
6603
  var DescriptionListDesc = /*#__PURE__*/React.forwardRef(function (props, ref) {
6528
6604
  var children = props.children,
6529
6605
  icon = props.icon,
@@ -8,8 +8,7 @@ import '../../helpers/styling/focus.js';
8
8
  import '../../helpers/styling/danger.js';
9
9
  import { selection } from '../../helpers/styling/selection.js';
10
10
  import { getBaseHTMLProps } from '../../types/BaseComponentProps.js';
11
- import { getFontStyling } from '../Typography/Typography.utils.js';
12
- import { descriptionListTokens, termTypographyTypes } from './DescriptionList.tokens.js';
11
+ import { descriptionListTokens } from './DescriptionList.tokens.js';
13
12
 
14
13
  var term = descriptionListTokens.term,
15
14
  desc = descriptionListTokens.desc,
@@ -19,7 +18,7 @@ var DList = styled.dl.withConfig({
19
18
  componentId: "sc-1ob73hm-0"
20
19
  })(["margin:0;*::selection{", "}", " display:flex;flex-direction:column;&:not(:has(> dt):has(> dd)){flex-direction:", ";}flex-wrap:wrap;column-gap:", ";row-gap:0;& > dt:first-of-type{margin-top:", ";}& > dd:last-child{margin-bottom:", ";}dd + dt{margin-top:", ";}"], selection, function (_ref) {
21
20
  var appearance = _ref.appearance;
22
- return appearance && css(["dt{color:", ";", " ", "}"], term.appearance[appearance].color, getFontStyling(termTypographyTypes[appearance]), appearance === 'bold' && css(["font-weight:600;"]));
21
+ return appearance && css(["dt{color:", ";", "}"], term.appearance[appearance].color, appearance === 'bold' && css(["font-weight:600;"]));
23
22
  }, function (_ref2) {
24
23
  var _ref2$direction = _ref2.direction,
25
24
  direction = _ref2$direction === void 0 ? 'column' : _ref2$direction;
@@ -1,9 +1,3 @@
1
- import { StaticTypographyType } from '../Typography';
2
- import { DescriptionListAppearance } from './DescriptionList';
3
- export declare const termTypographyTypes: {
4
- [k in DescriptionListAppearance]: StaticTypographyType;
5
- };
6
- export declare const descTypographyType: StaticTypographyType;
7
1
  export declare const descriptionListTokens: {
8
2
  term: {
9
3
  appearance: {
@@ -2,11 +2,6 @@ import { ddsBaseTokens } from '@norges-domstoler/dds-design-tokens';
2
2
 
3
3
  var spacing = ddsBaseTokens.spacing,
4
4
  colors = ddsBaseTokens.colors;
5
- var termTypographyTypes = {
6
- bold: 'bodySans03',
7
- small: 'bodySans01'
8
- };
9
- var descTypographyType = 'bodySans03';
10
5
  var term = {
11
6
  appearance: {
12
7
  small: {
@@ -49,4 +44,4 @@ var descriptionListTokens = {
49
44
  group: group
50
45
  };
51
46
 
52
- export { descTypographyType, descriptionListTokens, termTypographyTypes };
47
+ export { descriptionListTokens };
@@ -2,15 +2,14 @@ import { __rest } from 'tslib';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
3
  import { forwardRef } from 'react';
4
4
  import styled from 'styled-components';
5
- import { descriptionListTokens, descTypographyType } from './DescriptionList.tokens.js';
5
+ import { descriptionListTokens } from './DescriptionList.tokens.js';
6
6
  import { Icon } from '../Icon/Icon.js';
7
7
  import { getBaseHTMLProps } from '../../types/BaseComponentProps.js';
8
- import { getFontStyling } from '../Typography/Typography.utils.js';
9
8
 
10
9
  var DListDesc = styled.dd.withConfig({
11
10
  displayName: "DescriptionListDesc__DListDesc",
12
11
  componentId: "sc-1djcf0s-0"
13
- })(["margin-inline-start:0;align-items:center;display:flex;color:", ";", " gap:", ";"], descriptionListTokens.desc.base.color, getFontStyling(descTypographyType), descriptionListTokens.desc.base.gap);
12
+ })(["margin-inline-start:0;align-items:center;display:flex;color:", ";gap:", ";"], descriptionListTokens.desc.base.color, descriptionListTokens.desc.base.gap);
14
13
  var DescriptionListDesc = /*#__PURE__*/forwardRef(function (props, ref) {
15
14
  var children = props.children,
16
15
  icon = props.icon,
@@ -6,9 +6,15 @@ type StyledInlineInputProps = {
6
6
  };
7
7
  export declare const StyledInlineInput: import("styled-components").StyledComponent<"input", any, Pick<import("../../helpers").InputProps, "disabled" | "readOnly"> & {
8
8
  hasErrorMessage: boolean;
9
+ } & {
10
+ prefixLength?: number | undefined;
11
+ suffixLength?: number | undefined;
9
12
  } & Pick<import("../../helpers").InputProps, "componentSize"> & StyledInlineInputProps, never>;
10
13
  export declare const StyledInlineTextArea: import("styled-components").StyledComponent<"input", any, Pick<import("../../helpers").InputProps, "disabled" | "readOnly"> & {
11
14
  hasErrorMessage: boolean;
15
+ } & {
16
+ prefixLength?: number | undefined;
17
+ suffixLength?: number | undefined;
12
18
  } & Pick<import("../../helpers").InputProps, "componentSize"> & StyledInlineInputProps, never>;
13
19
  export declare const IconWrapper: import("styled-components").StyledComponent<"span", any, {}, never>;
14
20
  export {};
@@ -2,6 +2,9 @@ import { TextareaHTMLAttributes } from 'react';
2
2
  import { CommonInputProps } from '../../helpers/Input';
3
3
  export declare const StyledTextArea: import("styled-components").StyledComponent<"input", any, Pick<import("../../helpers/Input").InputProps, "disabled" | "readOnly"> & {
4
4
  hasErrorMessage: boolean;
5
+ } & {
6
+ prefixLength?: number | undefined;
7
+ suffixLength?: number | undefined;
5
8
  } & Pick<import("../../helpers/Input").InputProps, "componentSize">, never>;
6
9
  export type TextAreaProps = CommonInputProps & TextareaHTMLAttributes<HTMLTextAreaElement>;
7
10
  export declare const TextArea: import("react").ForwardRefExoticComponent<CommonInputProps & TextareaHTMLAttributes<HTMLTextAreaElement> & import("react").RefAttributes<HTMLTextAreaElement>>;
@@ -5,4 +5,6 @@ export declare const TextInput: React.ForwardRefExoticComponent<import("../../he
5
5
  } & React.InputHTMLAttributes<HTMLInputElement> & {
6
6
  withCharacterCounter?: boolean | undefined;
7
7
  icon?: import("../../icons/utils").SvgIcon | undefined;
8
+ prefix?: string | undefined;
9
+ suffix?: string | undefined;
8
10
  } & React.RefAttributes<HTMLInputElement>>;
@@ -1,12 +1,12 @@
1
1
  import { slicedToArray as _slicedToArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import { __rest } from 'tslib';
3
3
  import { jsxs, jsx } from 'react/jsx-runtime';
4
- import { forwardRef, useState, useId } from 'react';
4
+ import { forwardRef, useState, useRef, useId, useLayoutEffect } from 'react';
5
5
  import CharCounter from './CharCounter.js';
6
6
  import '../../helpers/Backdrop/Backdrop.js';
7
7
  import '../../helpers/Chevron/AnimatedChevronUpDown.styles.js';
8
8
  import '../../helpers/HiddenInput/HiddenInput.js';
9
- import { OuterInputContainer, InputContainer, StatefulInput } from '../../helpers/Input/Input.styles.js';
9
+ import { InputContainer, InputAffixContainer, StatefulInput, OuterInputContainer } from '../../helpers/Input/Input.styles.js';
10
10
  import '../../helpers/Input/Input.tokens.js';
11
11
  import { getDefaultText, getFormInputIconSize, renderInputMessage } from '../../helpers/Input/Input.utils.js';
12
12
  import '../../helpers/Paper/Paper.js';
@@ -19,6 +19,8 @@ import { StyledIcon, StyledInput, MessageContainer } from './TextInput.styles.js
19
19
  import '../Typography/Typography/Typography.js';
20
20
  import { Label } from '../Typography/Label/Label.js';
21
21
  import '../Typography/Link/Link.js';
22
+ import styled from 'styled-components';
23
+ import { textInputTokens } from './TextInput.tokens.js';
22
24
 
23
25
  var defaultWidth = '320px';
24
26
  var defaultTinyWidth = '210px';
@@ -29,6 +31,20 @@ var getWidth = function getWidth(size, width) {
29
31
  }
30
32
  return defaultWidth;
31
33
  };
34
+ var Prefix = styled.span.withConfig({
35
+ displayName: "TextInput__Prefix",
36
+ componentId: "sc-k8umq3-0"
37
+ })(["position:absolute;height:100%;top:50%;transform:translateY(-50%);display:flex;align-items:center;pointer-events:none;z-index:1;margin-left:8px;padding-right:8px;border-right:", ";"], function (_ref) {
38
+ var readOnly = _ref.readOnly;
39
+ return !readOnly && "1px solid ".concat(textInputTokens.affix.border.color);
40
+ });
41
+ var Suffix = styled.span.withConfig({
42
+ displayName: "TextInput__Suffix",
43
+ componentId: "sc-k8umq3-1"
44
+ })(["position:absolute;height:100%;top:50%;right:0;transform:translateY(-50%);display:flex;align-items:center;pointer-events:none;z-index:1;margin-right:8px;padding-left:8px;border-left:", ";"], function (_ref2) {
45
+ var readOnly = _ref2.readOnly;
46
+ return !readOnly && "1px solid ".concat(textInputTokens.affix.border.color);
47
+ });
32
48
  var TextInput = /*#__PURE__*/forwardRef(function (_a, ref) {
33
49
  var label = _a.label,
34
50
  disabled = _a.disabled,
@@ -53,11 +69,23 @@ var TextInput = /*#__PURE__*/forwardRef(function (_a, ref) {
53
69
  ariaRequired = _a['aria-required'],
54
70
  ariaDescribedby = _a['aria-describedby'],
55
71
  icon = _a.icon,
56
- rest = __rest(_a, ["label", "disabled", "readOnly", "errorMessage", "tip", "required", "maxLength", "onChange", "id", "width", "componentSize", "type", "withCharacterCounter", "className", "style", "value", "defaultValue", 'aria-required', 'aria-describedby', "icon"]);
72
+ prefix = _a.prefix,
73
+ suffix = _a.suffix,
74
+ rest = __rest(_a, ["label", "disabled", "readOnly", "errorMessage", "tip", "required", "maxLength", "onChange", "id", "width", "componentSize", "type", "withCharacterCounter", "className", "style", "value", "defaultValue", 'aria-required', 'aria-describedby', "icon", "prefix", "suffix"]);
57
75
  var _useState = useState(getDefaultText(value, defaultValue)),
58
76
  _useState2 = _slicedToArray(_useState, 2),
59
77
  text = _useState2[0],
60
78
  setText = _useState2[1];
79
+ var prefixRef = useRef(null);
80
+ var suffixRef = useRef(null);
81
+ var _useState3 = useState(0),
82
+ _useState4 = _slicedToArray(_useState3, 2),
83
+ prefixLength = _useState4[0],
84
+ setPrefixLength = _useState4[1];
85
+ var _useState5 = useState(0),
86
+ _useState6 = _slicedToArray(_useState5, 2),
87
+ suffixLength = _useState6[0],
88
+ setSuffixLength = _useState6[1];
61
89
  var onChangeHandler = function onChangeHandler(event) {
62
90
  setText(event.target.value);
63
91
  if (onChange) {
@@ -71,6 +99,7 @@ var TextInput = /*#__PURE__*/forwardRef(function (_a, ref) {
71
99
  var hasLabel = !!label;
72
100
  var hasMessage = hasErrorMessage || hasTip || !!maxLength;
73
101
  var hasIcon = !!icon;
102
+ var hasAffix = !!(prefix || suffix);
74
103
  var characterCounterId = derivativeIdGenerator(uniqueId, 'characterCounter');
75
104
  var tipId = derivativeIdGenerator(uniqueId, 'tip');
76
105
  var errorMessageId = derivativeIdGenerator(uniqueId, 'errorMessage');
@@ -95,13 +124,17 @@ var TextInput = /*#__PURE__*/forwardRef(function (_a, ref) {
95
124
  width: getWidth(componentSize, width)
96
125
  };
97
126
  var showRequiredStyling = !!(required || ariaRequired);
98
- return jsxs(OuterInputContainer, Object.assign({}, outerInputContainerProps, {
99
- children: [hasLabel && jsx(Label, Object.assign({
100
- htmlFor: uniqueId,
101
- showRequiredStyling: showRequiredStyling
102
- }, {
103
- children: label
104
- })), hasIcon ? jsxs(InputContainer, {
127
+ useLayoutEffect(function () {
128
+ if (prefixRef.current) {
129
+ setPrefixLength(prefixRef.current.offsetWidth);
130
+ }
131
+ if (suffixRef.current) {
132
+ setSuffixLength(suffixRef.current.offsetWidth);
133
+ }
134
+ }, []);
135
+ var extendedInput = null;
136
+ if (hasIcon) {
137
+ extendedInput = jsxs(InputContainer, {
105
138
  children: [jsx(StyledIcon, {
106
139
  icon: icon,
107
140
  iconSize: getFormInputIconSize(componentSize),
@@ -113,7 +146,38 @@ var TextInput = /*#__PURE__*/forwardRef(function (_a, ref) {
113
146
  componentSize: componentSize,
114
147
  hasIcon: hasIcon
115
148
  }, generalInputProps))]
116
- }) : jsx(StatefulInput, Object.assign({
149
+ });
150
+ } else if (hasAffix) {
151
+ extendedInput = jsxs(InputAffixContainer, {
152
+ children: [prefix && jsx(Prefix, Object.assign({
153
+ readOnly: readOnly,
154
+ ref: prefixRef,
155
+ "aria-hidden": true
156
+ }, {
157
+ children: prefix
158
+ })), jsx(StatefulInput, Object.assign({
159
+ ref: ref,
160
+ onChange: onChangeHandler,
161
+ type: type,
162
+ componentSize: componentSize,
163
+ prefixLength: prefixLength,
164
+ suffixLength: suffixLength
165
+ }, generalInputProps)), suffix && jsx(Suffix, Object.assign({
166
+ readOnly: readOnly,
167
+ ref: suffixRef,
168
+ "aria-hidden": true
169
+ }, {
170
+ children: suffix
171
+ }))]
172
+ });
173
+ }
174
+ return jsxs(OuterInputContainer, Object.assign({}, outerInputContainerProps, {
175
+ children: [hasLabel && jsx(Label, Object.assign({
176
+ htmlFor: uniqueId,
177
+ showRequiredStyling: showRequiredStyling
178
+ }, {
179
+ children: label
180
+ })), extendedInput ? extendedInput : jsx(StatefulInput, Object.assign({
117
181
  ref: ref,
118
182
  onChange: onChangeHandler,
119
183
  type: type,
@@ -6,6 +6,8 @@ declare const _default: {
6
6
  } & import("react").InputHTMLAttributes<HTMLInputElement> & {
7
7
  withCharacterCounter?: boolean | undefined;
8
8
  icon?: import("../../icons/utils").SvgIcon | undefined;
9
+ prefix?: string | undefined;
10
+ suffix?: string | undefined;
9
11
  } & import("react").RefAttributes<HTMLInputElement>>;
10
12
  argTypes: {
11
13
  label: {
@@ -56,3 +58,4 @@ export declare const TextInputOverviewSizes: () => JSX.Element;
56
58
  export declare const Default: (args: TextInputProps) => JSX.Element;
57
59
  export declare const WithLabel: (args: TextInputProps) => JSX.Element;
58
60
  export declare const WithCharacterCount: (args: TextInputProps) => JSX.Element;
61
+ export declare const TextInputAffixes: (args: TextInputProps) => JSX.Element;
@@ -10,5 +10,8 @@ type StyledInputProps = {
10
10
  };
11
11
  export declare const StyledInput: import("styled-components").StyledComponent<"input", any, Pick<import("../../helpers").InputProps, "disabled" | "readOnly"> & {
12
12
  hasErrorMessage: boolean;
13
+ } & {
14
+ prefixLength?: number | undefined;
15
+ suffixLength?: number | undefined;
13
16
  } & Pick<import("../../helpers").InputProps, "componentSize"> & StyledInputProps, never>;
14
17
  export {};
@@ -29,4 +29,9 @@ export declare const textInputTokens: {
29
29
  };
30
30
  };
31
31
  };
32
+ affix: {
33
+ border: {
34
+ color: string;
35
+ };
36
+ };
32
37
  };
@@ -16,6 +16,11 @@ var input = {
16
16
  }
17
17
  }
18
18
  };
19
+ var affix = {
20
+ border: {
21
+ color: colors.DdsColorNeutralsGray5
22
+ }
23
+ };
19
24
  var icon = {
20
25
  color: colors.DdsColorNeutralsGray9,
21
26
  sizes: {
@@ -35,7 +40,8 @@ var icon = {
35
40
  };
36
41
  var textInputTokens = {
37
42
  input: input,
38
- icon: icon
43
+ icon: icon,
44
+ affix: affix
39
45
  };
40
46
 
41
47
  export { textInputTokens };
@@ -5,4 +5,11 @@ export type TextInputProps = InputProps & {
5
5
  withCharacterCounter?: boolean;
6
6
  /** Ikonet som vises i komponenten. */
7
7
  icon?: SvgIcon;
8
+ /** Prefiks som vises før inputfeltet. */
9
+ prefix?: string;
10
+ /** Suffiks som vises etter inputfeltet. */
11
+ suffix?: string;
12
+ };
13
+ export type TextAffixProps = {
14
+ readOnly?: boolean;
8
15
  };
@@ -2,6 +2,9 @@ import { Property } from 'csstype';
2
2
  export declare const Input: import("styled-components").StyledComponent<"input", any, {}, never>;
3
3
  export declare const StatefulInput: import("styled-components").StyledComponent<"input", any, Pick<import("./Input.types").InputProps, "disabled" | "readOnly"> & {
4
4
  hasErrorMessage: boolean;
5
+ } & {
6
+ prefixLength?: number | undefined;
7
+ suffixLength?: number | undefined;
5
8
  } & Pick<import("./Input.types").InputProps, "componentSize">, never>;
6
9
  type OuterInputContainerProps = {
7
10
  width?: Property.Width;
@@ -9,4 +12,5 @@ type OuterInputContainerProps = {
9
12
  export declare const OuterInputContainer: import("styled-components").StyledComponent<"div", any, OuterInputContainerProps, never>;
10
13
  /**Brukes som container til input og ikon for posisjonering. */
11
14
  export declare const InputContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
15
+ export declare const InputAffixContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
12
16
  export {};
@@ -16,18 +16,24 @@ var Input = styled.input.withConfig({
16
16
  var StatefulInput = styled(Input).withConfig({
17
17
  displayName: "Inputstyles__StatefulInput",
18
18
  componentId: "sc-1oz9x8w-1"
19
- })(["-webkit-appearance:textfield;", " ", " &:enabled:read-only{border:none;outline:none;cursor:default;background-color:", ";padding-left:0;}&:disabled{cursor:not-allowed;color:", ";background-color:", ";}"], function (_ref) {
20
- var componentSize = _ref.componentSize;
21
- return componentSize && css(["padding:", ";", ""], input.sizes[componentSize].padding, getFontStyling(inputTypographyTypes[componentSize]));
19
+ })(["-webkit-appearance:textfield;padding-left:", ";padding-right:", ";", " ", " &:enabled:read-only{border:none;outline:none;cursor:default;background-color:", ";padding-left:0;}&:disabled{cursor:not-allowed;color:", ";background-color:", ";}"], function (_ref) {
20
+ var prefixLength = _ref.prefixLength;
21
+ return prefixLength && "calc(".concat(input.affix.gap, "px + ").concat(prefixLength, "px) !important");
22
22
  }, function (_ref2) {
23
- var hasErrorMessage = _ref2.hasErrorMessage;
23
+ var suffixLength = _ref2.suffixLength;
24
+ return suffixLength && "calc(".concat(input.affix.gap, "px + ").concat(suffixLength, "px) !important");
25
+ }, function (_ref3) {
26
+ var componentSize = _ref3.componentSize;
27
+ return componentSize && css(["padding:", ";", ""], input.sizes[componentSize].padding, getFontStyling(inputTypographyTypes[componentSize]));
28
+ }, function (_ref4) {
29
+ var hasErrorMessage = _ref4.hasErrorMessage;
24
30
  return hasErrorMessage && css(["", " &:hover:enabled:read-write{", "}&:focus:enabled:read-write,&:active:enabled:read-write{", "}"], dangerInputfield, hoverDangerInputfield, focusDangerInputfield);
25
31
  }, input.readOnly.backgroundColor, input.disabled.color, input.disabled.backgroundColor);
26
32
  var OuterInputContainer = styled.div.withConfig({
27
33
  displayName: "Inputstyles__OuterInputContainer",
28
34
  componentId: "sc-1oz9x8w-2"
29
- })(["position:relative;gap:", ";width:", ";"], container.gap, function (_ref3) {
30
- var width = _ref3.width;
35
+ })(["position:relative;gap:", ";width:", ";"], container.gap, function (_ref5) {
36
+ var width = _ref5.width;
31
37
  return width;
32
38
  });
33
39
  /**Brukes som container til input og ikon for posisjonering. */
@@ -35,5 +41,9 @@ var InputContainer = styled.div.withConfig({
35
41
  displayName: "Inputstyles__InputContainer",
36
42
  componentId: "sc-1oz9x8w-3"
37
43
  })(["position:relative;"]);
44
+ var InputAffixContainer = styled.div.withConfig({
45
+ displayName: "Inputstyles__InputAffixContainer",
46
+ componentId: "sc-1oz9x8w-4"
47
+ })(["position:relative;display:flex;align-items:center;"]);
38
48
 
39
- export { Input, InputContainer, OuterInputContainer, StatefulInput };
49
+ export { Input, InputAffixContainer, InputContainer, OuterInputContainer, StatefulInput };
@@ -28,6 +28,9 @@ export declare const inputTokens: {
28
28
  padding: string;
29
29
  };
30
30
  };
31
+ affix: {
32
+ gap: number;
33
+ };
31
34
  };
32
35
  container: {
33
36
  gap: string;
@@ -35,6 +35,9 @@ var input = {
35
35
  tiny: {
36
36
  padding: "".concat(spacing.SizesDdsSpacingLocalX025, " ").concat(spacing.SizesDdsSpacingLocalX05, " ").concat(spacing.SizesDdsSpacingLocalX025, " ").concat(spacing.SizesDdsSpacingLocalX05)
37
37
  }
38
+ },
39
+ affix: {
40
+ gap: spacing.SizesDdsSpacingLocalX1NumberPx
38
41
  }
39
42
  };
40
43
  var container = {
@@ -19,7 +19,10 @@ export type InputProps = CommonInputProps & {
19
19
  export type StyledCommonInputProps = Pick<InputProps, 'readOnly' | 'disabled'> & {
20
20
  hasErrorMessage: boolean;
21
21
  };
22
- export type StyledInputProps = StyledCommonInputProps & Pick<InputProps, 'componentSize'>;
22
+ export type StyledInputProps = StyledCommonInputProps & {
23
+ prefixLength?: number;
24
+ suffixLength?: number;
25
+ } & Pick<InputProps, 'componentSize'>;
23
26
  export type InputTypographyTypes = {
24
27
  [k in InputSize]: StaticTypographyType;
25
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@norges-domstoler/dds-components",
3
- "version": "13.0.2",
3
+ "version": "13.1.0",
4
4
  "description": "React components used in Elsa - domstolenes designsystem",
5
5
  "author": "Elsa team",
6
6
  "license": "MIT",