Skip to content

Commit

Permalink
feat: array size info based on min max Items properties (#1308)
Browse files Browse the repository at this point in the history
  • Loading branch information
mosheeshel authored Jun 27, 2020
1 parent 41b8b5d commit 644e96a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/Schema/ArraySchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Schema, SchemaProps } from './Schema';

import { ArrayClosingLabel, ArrayOpenningLabel } from '../../common-elements';
import styled from '../../styled-components';
import {humanizeConstraints} from "../../utils";

const PaddedSchema = styled.div`
padding-left: ${({ theme }) => theme.spacing.unit * 2}px;
Expand All @@ -12,9 +13,16 @@ const PaddedSchema = styled.div`
export class ArraySchema extends React.PureComponent<SchemaProps> {
render() {
const itemsSchema = this.props.schema.items!;
const itemConstraintSchema = (
min: number | undefined = undefined,
max: number | undefined = undefined,
) => ({ type: 'array', minItems: min, maxItems: max });

const minMaxItems = humanizeConstraints(itemConstraintSchema(itemsSchema.schema.minItems, itemsSchema.schema.maxItems));

return (
<div>
<ArrayOpenningLabel> Array </ArrayOpenningLabel>
<ArrayOpenningLabel> Array ({minMaxItems})</ArrayOpenningLabel>
<PaddedSchema>
<Schema {...this.props} schema={itemsSchema} />
</PaddedSchema>
Expand Down

0 comments on commit 644e96a

Please sign in to comment.