Simplify section styling

This commit is contained in:
Piotr Jamróz
2021-08-16 14:17:45 +02:00
parent bb462d8b12
commit 9822fed23e
5 changed files with 32 additions and 31 deletions
@@ -4,7 +4,7 @@ import { SegmentInput, Icon, SegmentSection } from '@grafana/ui';
const SegmentFrame = ({ children }: any) => ( const SegmentFrame = ({ children }: any) => (
<> <>
<SegmentSection label="Section Name">{children}</SegmentSection> <SegmentSection label="Segment Name">{children}</SegmentSection>
</> </>
); );
@@ -1,6 +1,9 @@
import React from 'react'; import React from 'react';
import { css } from '@emotion/css';
import { GrafanaTheme2 } from '@grafana/data';
import { SegmentSectionFill } from './SegmentSectionFill'; import { SegmentSectionFill } from './SegmentSectionFill';
import { SegmentSectionLabel } from './SegmentSectionLabel'; import { SegmentSectionLabel } from './SegmentSectionLabel';
import { useStyles2 } from '../../themes';
/** /**
* Horizontal section for editor components. * Horizontal section for editor components.
@@ -18,12 +21,26 @@ export const SegmentSection = ({
children: React.ReactNode; children: React.ReactNode;
// Fill the space at the end // Fill the space at the end
fill?: boolean; fill?: boolean;
}) => ( }) => {
<div className="gf-form-inline"> const styles = useStyles2(getStyles);
<div className="gf-form"> return (
<SegmentSectionLabel name={label} className="width-7" /> <>
{children} <div className={styles.container}>
</div> <div>
{fill && <SegmentSectionFill />} <SegmentSectionLabel name={label} className="width-7" />
</div> </div>
); {children}
{fill && <SegmentSectionFill />}
</div>
</>
);
};
const getStyles = (theme: GrafanaTheme2) => ({
container: css`
display: flex;
flex-wrap: wrap;
row-gap: ${theme.spacing(0.5)};
align-content: flex-start;
`,
});
@@ -82,6 +82,7 @@ const getStyles = (theme: GrafanaTheme2) => ({
borderRadius: theme.shape.borderRadius(), borderRadius: theme.shape.borderRadius(),
marginRight: theme.spacing(0.5), marginRight: theme.spacing(0.5),
padding: `0 ${theme.spacing(1)}`, padding: `0 ${theme.spacing(1)}`,
height: `${theme.v1.spacing.formInputHeight}px`,
}), }),
error: css` error: css`
border: 1px solid ${theme.colors.error.main}; border: 1px solid ${theme.colors.error.main};
@@ -2,8 +2,6 @@ import React from 'react';
import { GraphiteSegment } from '../types'; import { GraphiteSegment } from '../types';
import { GraphiteQueryEditorState } from '../state/store'; import { GraphiteQueryEditorState } from '../state/store';
import { MetricSegment } from './MetricSegment'; import { MetricSegment } from './MetricSegment';
import { css } from '@emotion/css';
import { useStyles2 } from '@grafana/ui';
type Props = { type Props = {
segments: GraphiteSegment[]; segments: GraphiteSegment[];
@@ -11,22 +9,11 @@ type Props = {
}; };
export function MetricsSection({ segments = [], state }: Props) { export function MetricsSection({ segments = [], state }: Props) {
const styles = useStyles2(getStyles);
return ( return (
<div className={styles.container}> <>
{segments.map((segment, index) => { {segments.map((segment, index) => {
return <MetricSegment segment={segment} metricIndex={index} key={index} state={state} />; return <MetricSegment segment={segment} metricIndex={index} key={index} state={state} />;
})} })}
</div> </>
); );
} }
function getStyles() {
return {
container: css`
display: flex;
flex-direction: row;
`,
};
}
@@ -44,7 +44,7 @@ export function TagsSection({ tags, state, addTagSegments }: Props) {
]); ]);
return ( return (
<div className={styles.container}> <>
{tags.map((tag, index) => { {tags.map((tag, index) => {
return <TagEditor key={index} tagIndex={index} tag={tag} state={state} />; return <TagEditor key={index} tagIndex={index} tag={tag} state={state} />;
})} })}
@@ -60,16 +60,12 @@ export function TagsSection({ tags, state, addTagSegments }: Props) {
/> />
)} )}
{state.paused && <PlayButton />} {state.paused && <PlayButton />}
</div> </>
); );
} }
function getStyles(theme: GrafanaTheme2) { function getStyles(theme: GrafanaTheme2) {
return { return {
container: css`
display: flex;
flex-direction: row;
`,
button: css` button: css`
margin-right: ${theme.spacing(0.5)}; margin-right: ${theme.spacing(0.5)};
`, `,