Skip to content

Commit

Permalink
docs(Separator): extend description for color prop (#3904)
Browse files Browse the repository at this point in the history
* docs(Separator): extend description for color prop

* docs(Separator): add typescript template to generate token type

* Update packages/orbit-components/src/Separator/README.md

Co-authored-by: Daniel Sil <daniel.sil@kiwi.com>

* chore(docs): prettify md and mdx files

Automatically changed via github action

---------

Co-authored-by: Daniel Sil <daniel.sil@kiwi.com>
Co-authored-by: mainframev <mainframev@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 28, 2023
1 parent 8dc2873 commit f8c9ee1
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 15 deletions.
20 changes: 18 additions & 2 deletions packages/orbit-components/config/typeFiles.mts
@@ -1,5 +1,6 @@
import { path, fs } from "zx";
import filedirname from "filedirname";
import { defaultTokens } from "@kiwicom/orbit-design-tokens";

import { NAMES as ILLUSTRATION_NAMES } from "../src/Illustration/consts.mjs";
import { NAMES as AIRPORT_ILLUSTRATION_NAMES } from "../src/AirportIllustration/consts.mjs";
Expand All @@ -8,6 +9,8 @@ import { NAME_OPTIONS as FEATURE_ICONS_NAMES } from "../src/FeatureIcon/consts.m

const [, __dirname] = filedirname();

const PALETTE_TOKENS = Object.keys(defaultTokens).filter(token => token.startsWith("palette"));

const generateTypeFile = async (templatePath: string, replacements: Record<string, string>) => {
const TEMPLATE = fs.readFileSync(templatePath, "utf8");

Expand All @@ -19,7 +22,7 @@ const generateTypeFile = async (templatePath: string, replacements: Record<strin
fs.writeFileSync(path.join(path.dirname(templatePath), "types.d.ts"), replacedTemplate);
};

const templateFiles = [
const templateIllustrationFiles = [
{
path: path.join(__dirname, "..", "src", "AirportIllustration", "TYPESCRIPT_TEMPLATE.template"),
names: AIRPORT_ILLUSTRATION_NAMES,
Expand All @@ -38,8 +41,21 @@ const templateFiles = [
},
];

templateFiles.forEach(arr => {
const templateTokensColors = [
{
path: path.join(__dirname, "..", "src", "Separator", "TYPESCRIPT_TEMPLATE.template"),
tokens: Object.values(PALETTE_TOKENS),
},
];

templateIllustrationFiles.forEach(arr => {
generateTypeFile(arr.path, {
NAMES: `${arr.names.map(item => `\n | "${String(item)}"`).join("")};`,
});
});

templateTokensColors.forEach(arr => {
generateTypeFile(arr.path, {
TOKENS: `${arr.tokens.map(item => `\n | "${String(item)}"`).join("")};`,
});
});
16 changes: 8 additions & 8 deletions packages/orbit-components/src/Separator/README.md
Expand Up @@ -16,14 +16,14 @@ After adding import to your project you can use it simply like:

The table below contains all types of props available in the Separator component.

| Name | Type | Default | Description |
| :--------- | :-------------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| indent | [`enum`](#enum) | `"none"` | Amount of padding expressed as [spacing tokens](https://orbit.kiwi/foundation/spacing/) in the direction depending on the `align` prop. |
| align | [`enum`](#enum) | `"left"` | The direction of indentation. If `"center"` then it's indented from both sides. |
| spaceAfter | `enum` | | Additional `margin-bottom` after component. [See this docs](https://github.com/kiwicom/orbit/tree/master/packages/orbit-components/src/common/getSpacingToken) |
| dataTest | `string` | | Optional prop for testing purposes. |
| type | [`enum`](#enum) | `"none"` | The type of the separator. |
| color | `string` | | The color of the separator. |
| Name | Type | Default | Description |
| :--------- | :-------------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| indent | [`enum`](#enum) | `"none"` | Amount of padding expressed as [spacing tokens](https://orbit.kiwi/foundation/spacing/) in the direction depending on the `align` prop. |
| align | [`enum`](#enum) | `"left"` | The direction of indentation. If `"center"` then it's indented from both sides. |
| spaceAfter | `enum` | | Additional `margin-bottom` after component. [See this docs](https://github.com/kiwicom/orbit/tree/master/packages/orbit-components/src/common/getSpacingToken) |
| dataTest | `string` | | Optional prop for testing purposes. |
| type | [`enum`](#enum) | `"none"` | The type of the separator. |
| color | `string` | | The color of the separator. You will need to pass a value different than `"none"` to the `type` property, as it's required for color to be shown. The value should be a string name of the token, for instance: "paletteBlueNormal" or "paletteProductNormal" |

### enum

Expand Down
4 changes: 2 additions & 2 deletions packages/orbit-components/src/Separator/Separator.stories.tsx
Expand Up @@ -3,7 +3,7 @@ import { select, text } from "@storybook/addon-knobs";

import SPACINGS_AFTER from "../common/getSpacingToken/consts";
import RenderInRtl from "../utils/rtl/RenderInRtl";
import type { Indent } from "./types";
import type { PaletteTokens, Indent } from "./types";

import Separator from ".";

Expand All @@ -24,7 +24,7 @@ export const Playground = () => {
const align = select("align", ["left", "right", "center"], "left");
const indentOptions: Indent[] = ["none", "small", "medium", "large", "XLarge", "XXLarge"];
const type = select("type", ["solid", "dashed", "dotted", "double", "none"], "none");
const color = text("color", "");
const color = text("color", "paletteBlueNormal") as PaletteTokens;
const indent = select("indent", indentOptions, "none");
return (
<Separator color={color} align={align} indent={indent} spaceAfter={spaceAfter} type={type} />
Expand Down
@@ -0,0 +1,15 @@
// Type definitions for @kiwicom/orbit-components
// Project: http://github.com/kiwicom/orbit
import type * as Common from "../common/types";

export type Indent = "none" | "small" | "medium" | "large" | "XLarge" | "XXLarge";
export type Align = "left" | "center" | "right";

export type PaletteTokens =%TOKENS%

export interface Props extends Common.SpaceAfter {
indent?: Indent;
type?: "solid" | "dashed" | "dotted" | "double" | "none";
color?: PaletteTokens;
align?: Align;
}
8 changes: 6 additions & 2 deletions packages/orbit-components/src/Separator/index.tsx
Expand Up @@ -37,7 +37,7 @@ const StyledContainer = styled.div<{ $align: Align; $indent: Indent }>`
export const StyledSeparator = styled.hr<{
spaceAfter?: Common.SpaceAfterSizes;
$type: Props["type"];
$color: Props["color"];
$color?: Props["color"];
}>`
${({ theme, $type, $color }) => css`
height: ${theme.orbit.heightSeparator};
Expand All @@ -64,7 +64,11 @@ const Separator = ({
const theme = useTheme();
return (
<StyledContainer $align={align} $indent={indent}>
<StyledSeparator $type={type} spaceAfter={spaceAfter} $color={color && theme.orbit[color]} />
<StyledSeparator
$type={type}
spaceAfter={spaceAfter}
$color={color && (theme.orbit[color] as Props["color"])}
/>
</StyledContainer>
);
};
Expand Down
80 changes: 79 additions & 1 deletion packages/orbit-components/src/Separator/types.d.ts
Expand Up @@ -5,9 +5,87 @@ import type * as Common from "../common/types";
export type Indent = "none" | "small" | "medium" | "large" | "XLarge" | "XXLarge";
export type Align = "left" | "center" | "right";

export type PaletteTokens =
| "paletteProductLight"
| "paletteProductLightHover"
| "paletteProductLightActive"
| "paletteProductNormal"
| "paletteProductNormalHover"
| "paletteProductNormalActive"
| "paletteProductDark"
| "paletteProductDarkHover"
| "paletteProductDarkActive"
| "paletteProductDarker"
| "paletteWhite"
| "paletteWhiteHover"
| "paletteWhiteActive"
| "paletteCloudLight"
| "paletteCloudLightHover"
| "paletteCloudLightActive"
| "paletteCloudNormal"
| "paletteCloudNormalHover"
| "paletteCloudNormalActive"
| "paletteCloudDark"
| "paletteCloudDarkHover"
| "paletteCloudDarkActive"
| "paletteInkLight"
| "paletteInkLightHover"
| "paletteInkLightActive"
| "paletteInkDark"
| "paletteInkDarkHover"
| "paletteInkDarkActive"
| "paletteInkNormal"
| "paletteInkNormalHover"
| "paletteInkNormalActive"
| "paletteOrangeLight"
| "paletteOrangeLightHover"
| "paletteOrangeLightActive"
| "paletteOrangeNormal"
| "paletteOrangeNormalHover"
| "paletteOrangeNormalActive"
| "paletteOrangeDark"
| "paletteOrangeDarkHover"
| "paletteOrangeDarkActive"
| "paletteOrangeDarker"
| "paletteRedLight"
| "paletteRedLightHover"
| "paletteRedLightActive"
| "paletteRedNormal"
| "paletteRedNormalHover"
| "paletteRedNormalActive"
| "paletteRedDark"
| "paletteRedDarkHover"
| "paletteRedDarkActive"
| "paletteRedDarker"
| "paletteGreenLight"
| "paletteGreenLightHover"
| "paletteGreenLightActive"
| "paletteGreenNormal"
| "paletteGreenNormalHover"
| "paletteGreenNormalActive"
| "paletteGreenDark"
| "paletteGreenDarkHover"
| "paletteGreenDarkActive"
| "paletteGreenDarker"
| "paletteBlueLight"
| "paletteBlueLightHover"
| "paletteBundleBasic"
| "paletteBundleMedium"
| "paletteBlueLightActive"
| "paletteBlueNormal"
| "paletteBlueNormalHover"
| "paletteBlueNormalActive"
| "paletteBlueDark"
| "paletteBlueDarkHover"
| "paletteBlueDarkActive"
| "paletteBlueDarker"
| "paletteSocialFacebook"
| "paletteSocialFacebookHover"
| "paletteSocialFacebookActive";

export interface Props extends Common.SpaceAfter {
indent?: Indent;
type?: "solid" | "dashed" | "dotted" | "double" | "none";
color?: string;
color?: PaletteTokens;
align?: Align;
}

0 comments on commit f8c9ee1

Please sign in to comment.