Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions src/components/field/field-depth.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import styled from '@emotion/styled';
import { spacing } from '@leafygreen-ui/tokens';
import { palette } from '@leafygreen-ui/palette';

import { DEFAULT_FIELD_HEIGHT } from '@/utilities/constants';
import { DEFAULT_DEPTH_SPACING, DEFAULT_FIELD_HEIGHT } from '@/utilities/constants';

const FieldDepthWrapper = styled.div`
padding-right: ${spacing[200]}px;
padding-right: ${DEFAULT_DEPTH_SPACING}px;
height: ${DEFAULT_FIELD_HEIGHT}px;
border-left: 1px solid ${palette.gray.dark2};
`;
Expand Down
3 changes: 3 additions & 0 deletions src/components/field/field-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { spacing } from '@leafygreen-ui/tokens';

import { Field } from '@/components/field/field';
import { NodeField } from '@/types';
import { getPreviewGroupLengths } from '@/utilities/get-preview-group-lengths';

const NodeFieldWrapper = styled.div`
padding: ${spacing[200]}px ${spacing[400]}px ${spacing[200]}px ${spacing[400]}px;
Expand All @@ -16,13 +17,15 @@ interface Props {

export const FieldList = ({ fields, accent }: Props) => {
const spacing = Math.max(0, ...fields.map(field => field.glyphs?.length || 0));
const previewGroupLength = getPreviewGroupLengths(fields);
return (
<NodeFieldWrapper>
{fields.map(({ name, type: fieldType, depth, glyphs, variant }) => (
<Field
key={name}
name={name}
depth={depth}
previewGroupLength={previewGroupLength[name]}
accent={accent}
glyphs={glyphs}
type={fieldType}
Expand Down
79 changes: 69 additions & 10 deletions src/components/field/field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { palette } from '@leafygreen-ui/palette';
import Icon from '@leafygreen-ui/icon';
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';

import { ellipsisTruncation } from '@/styles/styles';
import { DEFAULT_FIELD_HEIGHT } from '@/utilities/constants';
import { animatedBlueBorder, ellipsisTruncation } from '@/styles/styles';
import { DEFAULT_DEPTH_SPACING, DEFAULT_FIELD_HEIGHT } from '@/utilities/constants';
import { FieldDepth } from '@/components/field/field-depth';
import { NodeField, NodeGlyph } from '@/types';

const FIELD_BORDER_ANIMATED_PADDING = spacing[100];
const FIELD_GLYPH_SPACING = spacing[400];

const GlyphToIcon: Record<NodeGlyph, string> = {
key: 'Key',
link: 'Link',
Expand All @@ -26,7 +29,37 @@ const InnerFieldWrapper = styled.div<{ width: number }>`
display: flex;
justify-content: flex-end;
flex: 0 0 auto;
width: ${props => `${props.width * spacing[400]}px`};
width: ${props => `${props.width * FIELD_GLYPH_SPACING}px`};
`;

const FieldBorderAnimated = styled.div<{ height: string; left: string; width: string }>`
position: relative;

&::before {
content: '';
position: absolute;
width: ${props => props.width};
height: ${props => props.height};
left: ${props => props.left};
top: ${FIELD_BORDER_ANIMATED_PADDING / 2}px;
${animatedBlueBorder};
padding: ${FIELD_BORDER_ANIMATED_PADDING}px;
margin: -${FIELD_BORDER_ANIMATED_PADDING}px;
}
`;

const FieldBorder = styled(FieldBorderAnimated)`
display: flex;
min-width: 0;
flex: 1;
align-items: center;
`;

const FieldRow = styled.div`
display: flex;
min-width: 0;
flex: 1;
align-items: center;
`;

const FieldName = styled.div`
Expand Down Expand Up @@ -58,9 +91,19 @@ const IconWrapper = styled(Icon)`
interface Props extends NodeField {
accent: string;
spacing: number;
previewGroupLength?: number;
}

export const Field = ({ name, depth, type, glyphs, accent, spacing, variant }: Props) => {
export const Field = ({
name,
depth = 0,
type,
glyphs = [],
accent,
spacing = 0,
variant,
previewGroupLength = 0,
}: Props) => {
const { theme } = useDarkMode();

const getTextColor = () => {
Expand Down Expand Up @@ -89,18 +132,34 @@ export const Field = ({ name, depth, type, glyphs, accent, spacing, variant }: P
}
};

const content = (
<>
<FieldName>
<FieldDepth depth={depth} />
<InnerFieldName>{name}</InnerFieldName>
</FieldName>
<FieldType color={getSecondaryTextColor()}>{type}</FieldType>
</>
);

return (
<FieldWrapper color={getTextColor()}>
<InnerFieldWrapper width={spacing}>
{glyphs?.map(glyph => (
{glyphs.map(glyph => (
<IconWrapper key={glyph} size={11} color={getIconColor(glyph)} glyph={GlyphToIcon[glyph]} />
))}
</InnerFieldWrapper>
<FieldName>
<FieldDepth depth={depth || 0} />
<InnerFieldName>{name}</InnerFieldName>
</FieldName>
<FieldType color={getSecondaryTextColor()}>{type}</FieldType>
{previewGroupLength ? (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, this addresses the bug @adrianhhong discovered yesterday!

context: with our most recently released version, when using wrapped keys, renaming a field in an embedded document or array mapping to _id.*, the renamed field will bubble up to the parent document' _id object

<FieldBorder
height={`${previewGroupLength * DEFAULT_FIELD_HEIGHT - FIELD_BORDER_ANIMATED_PADDING / 2}px`}
left={`${depth * DEFAULT_DEPTH_SPACING - glyphs.length * FIELD_GLYPH_SPACING}px`}
width={`calc(100% + ${glyphs.length * FIELD_GLYPH_SPACING - depth * FIELD_BORDER_ANIMATED_PADDING * 2}px)`}
>
{content}
</FieldBorder>
) : (
<FieldRow>{content}</FieldRow>
)}
</FieldWrapper>
);
};
26 changes: 6 additions & 20 deletions src/components/node/node-border.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
import { PropsWithChildren } from 'react';
import styled from '@emotion/styled';
import { palette } from '@leafygreen-ui/palette';
import { css, keyframes } from '@emotion/react';
import { css } from '@emotion/react';
import { spacing } from '@leafygreen-ui/tokens';

import { NodeBorderVariant } from '@/types';
import { DEFAULT_NODE_WIDTH } from '@/utilities/constants';

export const rotateAnimation = keyframes({
'0%': {
backgroundPosition: 'left top, right bottom, left bottom, right top',
},
'100%': {
backgroundPosition: 'left 15px top, right 15px bottom, left bottom 15px, right top 15px',
},
});
import { animatedBlueBorder } from '@/styles/styles';

const borderProperties = css`
border-radius: ${spacing[200]}px;
width: ${DEFAULT_NODE_WIDTH + spacing[50]}px;
`;

export const AnimatedBorder = styled.div`
background: linear-gradient(90deg, ${palette.blue.base} 50%, transparent 50%),
linear-gradient(90deg, ${palette.blue.base} 50%, transparent 50%),
linear-gradient(0deg, ${palette.blue.base} 50%, transparent 50%),
linear-gradient(0deg, ${palette.blue.base} 50%, transparent 50%);
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: left top, right bottom, left bottom, right top;
background-size: 15px 2px, 15px 2px, 2px 15px, 2px 15px;
export const AnimatedBorder = styled.div<{ height?: string }>`
height: ${props => (props.height ? props.height : '100%')};
padding: ${spacing[100]}px;
margin: -${spacing[100]}px;
animation: ${rotateAnimation} 1s linear infinite;
${borderProperties}
${animatedBlueBorder};
${borderProperties};
`;

const BasicBorder = styled.div<{ outlineBorderColor?: string }>`
Expand Down
Loading