Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core): fix ink-divider warning message #6851

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 21 additions & 26 deletions core/src/util/ink-divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

/**
The MIT License (MIT)

Copyright (c) 2018-present Jure Sotošek

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -32,7 +32,6 @@

import React from "react"
import { Box, Text } from "ink"
import PropTypes from "prop-types"
import stringWidth from "string-width"

// Adapted from https://github.com/JureSotosek/ink-divider due to ESM incompatibilities
Expand All @@ -44,7 +43,23 @@ const getNumberOfCharsPerWidth = (char, width) => width / stringWidth(char)
const PAD = " "

// Divider
const Divider = ({ title, width, padding, titlePadding, titleColor, dividerChar, dividerColor }) => {
const Divider = ({
title = null,
width = 50,
padding = 1,
titlePadding = 1,
titleColor = "white",
dividerChar = "-",
dividerColor = "grey",
}: {
title: string | null
width?: number
padding?: number
titlePadding?: number
titleColor?: string
dividerChar?: string
dividerColor?: string
}) => {
const titleString = title ? `${PAD.repeat(titlePadding) + title + PAD.repeat(titlePadding)}` : ""
const titleWidth = stringWidth(titleString)

Expand All @@ -67,24 +82,4 @@ const Divider = ({ title, width, padding, titlePadding, titleColor, dividerChar,
)
}

Divider.propTypes = {
title: PropTypes.string,
width: PropTypes.number,
padding: PropTypes.number,
titlePadding: PropTypes.number,
titleColor: PropTypes.string,
dividerChar: PropTypes.string,
dividerColor: PropTypes.string,
}

Divider.defaultProps = {
title: null,
width: 50,
padding: 1,
titlePadding: 1,
titleColor: "white",
dividerChar: "─",
dividerColor: "grey",
}

export default Divider