Skip to content

Commit

Permalink
Merge pull request #114 from amir78729/docs/jsdoc/text-field
Browse files Browse the repository at this point in the history
docs: add JSDoc to `text-field` component
  • Loading branch information
amir78729 authored May 28, 2024
2 parents c35ba42 + b17bf3c commit b63454d
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 67 deletions.
34 changes: 17 additions & 17 deletions src/stepper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ import styles from './stepper.style.js';
* ```
* @summary A form item that shows a value and can be increased or decreased by tw buttons
*
* @prop {string} [unit=''] - A single quantity of the value
* @prop {boolean} disabled - If `true`, the component is disabled.
* @prop {number} [step="1"] - The number to which the current value is increased or decreased.
* @prop {`string`} [`unit`=`''`] - A single quantity of the value
* @prop {`boolean`} [`disabled`=`false`] - If `true`, the component is disabled.
* @prop {`number`} [`step`=`1`] - The number to which the current value is increased or decreased.
* It can be an integer or decimal
* @prop {'small' | 'medium'} [size='medium'] - The size of icons and font.
* @prop {number} min - The min value.
* @prop {number} max - The max value.
* @prop {number} fullWidth - If `true` the component will fill the parent.
* @prop {number} [value="0"] - The current value.
* @prop {`'small'` \| `'medium'`} [`size`=`'medium'`] - The size of icons and font.
* @prop {`number`} [`min`=`-Infinity`] - The min value.
* @prop {`number`} [`max`=`Infinity`] - The max value.
* @prop {`number`} [`fullWidth`=`false`] - If `true` the component will fill the parent.
* @prop {`number`} [`value`=`0`] - The current value.
*
* @fires {CustomEvent} - Stepper change event
* @fires {`CustomEvent`} - Stepper change event
*
* @csspart stepper - The container that wraps the stepper component.
* @csspart decrease-button - The button that contains minus icon and decrease the value.
* @csspart increase-button - The button that contains plus icon and increases the value.
* @csspart value - The `p` tag that shows the `value`.
* @csspart unit - The `p` tag that shows the `unit` and will be hidden if `unit` not exists.
* @csspart `stepper` - The container that wraps the stepper component.
* @csspart `decrease-button` - The button that contains minus icon and decrease the value.
* @csspart `increase-button` - The button that contains plus icon and increases the value.
* @csspart `value` - The `p` tag that shows the `value`.
* @csspart `unit` - The `p` tag that shows the `unit` and will be hidden if `unit` not exists.
*
* @cssprop [--tap-font-family=--tap-sys-font-family]
* @cssprop [--tap-stepper-typography-label-sm-size=--tap-sys-typography-label-md-size]
* @cssprop [--tap-stepper-typography-label-md-size=--tap-sys-typography-label-lg-size]
* @cssprop [`--tap-font-family`=`--tap-sys-font-family`]
* @cssprop [`--tap-stepper-typography-label-sm-size`=`--tap-sys-typography-label-md-size`]
* @cssprop [`--tap-stepper-typography-label-md-size`=`--tap-sys-typography-label-lg-size`]
*/
@customElement('tap-stepper')
export class TapStepper extends Stepper {
Expand Down
76 changes: 71 additions & 5 deletions src/text-field/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,80 @@
import { customElement } from "lit/decorators.js";
import { TextField } from "./text-field";
import styles from "./text-field.style";
import { customElement } from 'lit/decorators.js';
import { TextField } from './text-field';
import styles from './text-field.style';

@customElement("tap-text-field")
/**
* ### Example
*
*
* ##### Simple
*
* ```html
* <tap-text-field></tap-text-field>
* ```
*
* ##### With Label and Placeholder
*
* ```html
* <tap-text-field label="Name" placeholder="Enter your name"></tap-text-field>
* ```
*
* @summary A text field component.
*
* @prop {`string`} [`value`=`''`] - The value of the text field.
* @prop {`boolean`} [`disabled`=`false`] - Indicates whether the text field is disabled.
* @prop {`boolean`} [`error`=`false`] - Indicates whether the text field has an error.
* @prop {`string`} [`caption`=`''`] - The caption text for the text field.
* @prop {`string`} [`label`=`''`] - The label for the text field.
* @prop {`string`} [`name`=`''`] - The name of the text field.
* @prop {`string`} [`placeholder`=`''`] - The placeholder text for the text field.
* @prop {`string`} [`inputmode`=`''`] - The input mode for the text field.
* @prop {`string`} [`type`=`''`] - The type of the text field.
* @prop {`string`} [`autocomplete`=`''`] - The autocomplete attribute for the text field.
*
* @csspart [`field`] - The main container for the text field.
* @csspart [`label`] - The label for the text field.
* @csspart [`container`] - The container for the input and any leading/trailing elements.
* @csspart [`input`] - The input element.
* @csspart [`caption`] - The caption for the text field.
*
* @cssprop [`--tap-font-family`=`--tap-sys-font-family`] - The font family used in the text field.
* @cssprop [`--tap-text-field-field-gap`=`--tap-sys-spacing-4`] - The gap between the elements in the text field.
* @cssprop [`--tap-text-field-label-color`=`--tap-sys-color-content-primary`] - The color of the label.
* @cssprop [`--tap-text-field-label-line-height`=`--tap-sys-typography-label-sm-height`] - The line height of the label.
* @cssprop [`--tap-text-field-label-font-size`=`--tap-sys-typography-label-sm-size`] - The font size of the label.
* @cssprop [`--tap-text-field-label-font-weight`=`--tap-sys-typography-label-sm-weight`] - The font weight of the label.
* @cssprop [`--tap-text-field-caption-color`=`--tap-sys-color-content-tertiary`] - The color of the caption.
* @cssprop [`--tap-text-field-caption-line-height`=`--tap-sys-typography-body-sm-height`] - The line height of the caption.
* @cssprop [`--tap-text-field-caption-font-size`=`--tap-sys-typography-body-sm-size`] - The font size of the caption.
* @cssprop [`--tap-text-field-caption-font-weight`=`--tap-sys-typography-body-sm-weight`] - The font weight of the caption.
* @cssprop [`--tap-text-field-container-height`=`--tap-sys-spacing-11`] - The height of the container.
* @cssprop [`--tap-text-field-container-padding`=`--tap-sys-spacing-6`] - The padding inside the container.
* @cssprop [`--tap-text-field-container-gap`=`--tap-sys-spacing-4`] - The gap between elements in the container.
* @cssprop [`--tap-text-field-container-background-color`=`--tap-sys-color-surface-tertiary`] - The background color of the container.
* @cssprop [`--tap-text-field-container-border-radius`=`--tap-sys-radius-3`] - The border radius of the container.
* @cssprop [`--tap-text-field-focus-background-color`=`--tap-sys-color-surface-secondary`] - The background color of the container when focused.
* @cssprop [`--tap-text-field-focus-border-width`=`--tap-sys-color-border-inverse-primary`] - The border width of the container when focused.
* @cssprop [`--tap-text-field-input-color`=`--tap-sys-color-content-primary`] - The color of the input text.
* @cssprop [`--tap-text-field-input-line-height`=`--tap-sys-typography-body-md-height`] - The line height of the input text.
* @cssprop [`--tap-text-field-input-font-size`=`--tap-sys-typography-body-md-size`] - The font size of the input text.
* @cssprop [`--tap-text-field-input-font-weight`=`--tap-sys-typography-body-md-weight`] - The font weight of the input text.
* @cssprop [`--tap-text-field-input-placeholder-color`=`--tap-sys-color-content-tertiary`] - The color of the placeholder text.
* @cssprop [`--tap-text-field-input-placeholder-line-height`=`--tap-sys-typography-body-md-height`] - The line height of the placeholder text.
* @cssprop [`--tap-text-field-input-placeholder-font-size`=`--tap-sys-typography-body-md-size`] - The font size of the placeholder text.
* @cssprop [`--tap-text-field-input-placeholder-font-weight`=`--tap-sys-typography-body-md-weight`] - The font weight of the placeholder text.
* @cssprop [`--tap-text-field-error-caption-color`=`--tap-sys-color-content-negative`] - The color of the caption when there is an error.
* @cssprop [`--tap-text-field-error-container-background-color`=`--tap-sys-color-surface-negative-light`] - The background color of the container when there is an error.
* @cssprop [`--tap-text-field-error-container-border-color`=`--tap-sys-color-border-negative`] - The border color of the container when there is an error.
* @cssprop [`--tap-text-field-disabled-container-background-color`=`--tap-sys-color-surface-disabled`] - The background color of the container when disabled.
* @cssprop [`--tap-text-field-disabled-container-color`=`--tap-sys-color-content-disabled`] - The color of the text and elements when disabled.
*/
@customElement('tap-text-field')
export class TapTextField extends TextField {
static readonly styles = [styles];
}

declare global {
interface HTMLElementTagNameMap {
"tap-text-field": TapTextField;
'tap-text-field': TapTextField;
}
}
8 changes: 4 additions & 4 deletions src/text-field/text-field.stories.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { html, TemplateResult } from "lit";
import "./text-field.js";
import { html, TemplateResult } from 'lit';
import './text-field.js';

export default {
title: "TextField",
component: "tap-text-field",
title: 'TextField',
component: 'tap-text-field',
argTypes: {},
};

Expand Down
138 changes: 107 additions & 31 deletions src/text-field/text-field.style.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { css } from "lit";
import { css } from 'lit';

export default css`
:host {
Expand All @@ -17,81 +17,157 @@ export default css`
.field {
direction: rtl;
font-family: var(--tap-sys-font-family);
font-family: var(--tap-font-family, var(--tap-sys-font-family));
display: flex;
flex-direction: column;
gap: var(--tap-sys-spacing-4);
gap: var(--tap-text-field-field-gap, var(--tap-sys-spacing-4));
}
.label {
color: var(--tap-sys-color-content-primary);
line-height: var(--tap-sys-typography-label-sm-height);
font-size: var(--tap-sys-typography-label-sm-size);
font-weight: var(--tap-sys-typography-label-sm-weight);
color: var(
--tap-text-field-label-color,
var(--tap-sys-color-content-primary)
);
line-height: var(
--tap-text-field-label-line-height,
var(--tap-sys-typography-label-sm-height)
);
font-size: var(
--tap-text-field-label-font-size,
var(--tap-sys-typography-label-sm-size)
);
font-weight: var(
--tap-text-field-label-font-weight,
var(--tap-sys-typography-label-sm-weight)
);
}
.caption {
color: var(--tap-sys-color-content-tertiary);
line-height: var(--tap-sys-typography-body-sm-height);
font-size: var(--tap-sys-typography-body-sm-size);
font-weight: var(--tap-sys-typography-body-sm-weight);
color: var(
--tap-text-field-caption-color,
var(--tap-sys-color-content-tertiary)
);
line-height: var(
--tap-text-field-caption-line-height,
var(--tap-sys-typography-body-sm-height)
);
font-size: var(
--tap-text-field-caption-font-size,
var(--tap-sys-typography-body-sm-size)
);
font-weight: var(
--tap-text-field-caption-font-weight,
var(--tap-sys-typography-body-sm-weight)
);
}
.container {
/* FIXME: height of the input is 52px but we dont have 52px in our tokens */
height: var(--tap-sys-spacing-11);
padding: 0 var(--tap-sys-spacing-6);
height: var(--tap-text-field-container-height, var(--tap-sys-spacing-11));
padding: 0 var(--tap-text-field-container-padding, var(--tap-sys-spacing-6));
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--tap-sys-spacing-4);
background-color: var(--tap-sys-color-surface-tertiary);
border-radius: var(--tap-sys-radius-3);
gap: var(--tap-text-field-container-gap, var(--tap-sys-spacing-4));
background-color: var(
--tap-text-field-container-background-color,
var(--tap-sys-color-surface-tertiary)
);
border-radius: var(
--tap-text-field-container-border-radius,
var(--tap-sys-radius-3)
);
border: 2px solid transparent;
}
.container:focus-within {
background-color: var(--tap-sys-color-surface-secondary);
border: 2px solid var(--tap-sys-color-border-inverse-primary);
background-color: var(
--tap-text-field-focus-background-color,
var(--tap-sys-color-surface-secondary)
);
border: 2px solid
var(
--tap-text-field-focus-border-width,
var(--tap-sys-color-border-inverse-primary)
);
}
.input {
border: 0;
outline: none;
flex: 1;
background-color: transparent;
color: var(--tap-sys-color-content-primary);
line-height: var(--tap-sys-typography-body-md-height);
font-size: var(--tap-sys-typography-body-md-size);
font-weight: var(--tap-sys-typography-body-md-weight);
color: var(
--tap-text-field-input-color,
var(--tap-sys-color-content-primary)
);
line-height: var(
--tap-text-field-input-line-height,
var(--tap-sys-typography-body-md-height)
);
font-size: var(
--tap-text-field-input-font-size,
var(--tap-sys-typography-body-md-size)
);
font-weight: var(
--tap-text-field-input-font-weight,
var(--tap-sys-typography-body-md-weight)
);
font-family: inherit;
}
.input::placeholder {
color: var(--tap-sys-color-content-tertiary);
line-height: var(--tap-sys-typography-body-md-height);
font-size: var(--tap-sys-typography-body-md-size);
font-weight: var(--tap-sys-typography-body-md-weight);
color: var(
--tap-text-field-input-placeholder-color,
var(--tap-sys-color-content-tertiary)
);
line-height: var(
--tap-text-field-input-placeholder-line-height,
var(--tap-sys-typography-body-md-height)
);
font-size: var(
--tap-text-field-input-placeholder-font-size,
var(--tap-sys-typography-body-md-size)
);
font-weight: var(
--tap-text-field-input-placeholder-font-weight,
var(--tap-sys-typography-body-md-weight)
);
font-family: inherit;
}
:host([error]) .caption {
color: var(--tap-sys-color-content-negative);
color: var(
--tap-text-field-error-caption-color,
var(--tap-sys-color-content-negative)
);
}
:host([error]) .container {
background-color: var(--tap-sys-color-surface-negative-light);
border-color: var(--tap-sys-color-border-negative);
background-color: var(
--tap-text-field-error-container-background-color,
var(--tap-sys-color-surface-negative-light)
);
border-color: var(
--tap-text-field-error-container-border-color,
var(--tap-sys-color-border-negative)
);
}
:host([disabled]) .container {
background-color: var(--tap-sys-color-surface-disabled);
background-color: var(
--tap-text-field-disabled-container-background-color,
var(--tap-sys-color-surface-disabled)
);
}
:host([disabled]) .caption,
:host([disabled]) .label,
:host([disabled]) .input,
:host([disabled]) .input::placeholder {
color: var(--tap-sys-color-content-disabled);
color: var(
--tap-text-field-disabled-container-color,
var(--tap-sys-color-content-disabled)
);
}
`;
Loading

0 comments on commit b63454d

Please sign in to comment.