Skip to content

Commit

Permalink
refactor: use styled emotion
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Jan 14, 2025
1 parent edbd91e commit fb89d97
Show file tree
Hide file tree
Showing 40 changed files with 289 additions and 399 deletions.
16 changes: 8 additions & 8 deletions src/component/1d-2d/FieldEdition.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @jsxImportSource @emotion/react */
import type { PopoverProps } from '@blueprintjs/core';
import { Popover } from '@blueprintjs/core';
import { css } from '@emotion/react';
import { Popover as BasePopover } from '@blueprintjs/core';
import styled from '@emotion/styled';
import { yupResolver } from '@hookform/resolvers/yup';
import type { ReactNode } from 'react';
import { useState } from 'react';
Expand All @@ -11,6 +10,12 @@ import * as Yup from 'yup';
import { Input2Controller } from '../elements/Input2Controller.js';
import { NumberInput2Controller } from '../elements/NumberInput2Controller.js';

const Popover = styled(BasePopover)`
.field-edition-popover {
border-radius: 5px;
}
`;

type InputType = 'number' | 'text';

interface FieldProps {
Expand Down Expand Up @@ -52,11 +57,6 @@ export function FieldEdition(props: FieldEditionsProps) {

return (
<Popover
css={css`
.field-edition-popover {
border-radius: 5px;
}
`}
popoverClassName="field-edition-popover"
isOpen={isOpen}
onClose={() => setIsOpen(false)}
Expand Down
8 changes: 3 additions & 5 deletions src/component/1d/ExclusionZoneAnnotation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { Filters1D } from 'nmr-processing';
import { memo } from 'react';

Expand All @@ -16,7 +15,7 @@ interface ExclusionZoneProps {
filterId: string;
}

const style = css`
const Rect = styled.rect`
&:hover {
fill: #ff6f0057 !important;
}
Expand All @@ -43,9 +42,8 @@ function ExclusionZoneAnnotation({

return (
<g key={zone.id} transform={`translate(${scaleX()(zone.to)},0)`}>
<rect
<Rect
x="0"
css={style}
transform={`translate(0,${scaleY()(0) - (vAlign + 5)})`}
width={`${scaleX()(zone.from) - scaleX()(zone.to)}`}
height="10px"
Expand Down
11 changes: 5 additions & 6 deletions src/component/1d/FooterBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { xFindClosestIndex } from 'ml-spectra-processing';
import type { ActiveSpectrum, Spectrum1D } from 'nmr-load-save';
import { memo } from 'react';
Expand All @@ -15,7 +14,7 @@ import { useActiveSpectrum } from '../hooks/useActiveSpectrum.js';
import { useFormatNumberByNucleus } from '../hooks/useFormatNumberByNucleus.js';
import useSpectrum from '../hooks/useSpectrum.js';

const styles = css`
const Container = styled.div`
display: flex;
align-items: center;
user-select: none;
Expand Down Expand Up @@ -112,7 +111,7 @@ function FooterBannerInner({
position.x > width - margin.right ||
position.y > height - margin.bottom
) {
return <div css={styles} />;
return <Container />;
}

function getXIndex(xPosition) {
Expand All @@ -135,7 +134,7 @@ function FooterBannerInner({
const isBrushing = step === 'brushing' && mouseButton === 'main';

return (
<div css={styles}>
<Container>
<BsCursor />
<div>
<span className="label"> 𝛅: </span>
Expand Down Expand Up @@ -210,7 +209,7 @@ function FooterBannerInner({
</div>
</div>
)}
</div>
</Container>
);
}

Expand Down
8 changes: 3 additions & 5 deletions src/component/1d/LinesSeries.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import type { Spectrum1D } from 'nmr-load-save';

import { get1DDataXY } from '../../data/data1d/Spectrum1D/get1DDataXY.js';
Expand All @@ -16,7 +15,7 @@ import { SPECTRA_BOTTOM_MARGIN } from './utilities/scale.js';

const BOX_SIZE = 10;

const style = css`
const Rect = styled.rect`
fill: transparent;
&:hover {
Expand Down Expand Up @@ -76,8 +75,7 @@ function HeadlightRectStackMode(props: HeadlightRectStackModeProps) {
}

return (
<rect
css={style}
<Rect
y={innerHeight - shiftY * index - BOX_SIZE / 2}
x={margin.left}
width={`${innerWidth}px`}
Expand Down
15 changes: 6 additions & 9 deletions src/component/1d/XAxis.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import * as d3 from 'd3';
import { useEffect, useRef } from 'react';

import { useChartData } from '../context/ChartContext.js';
import { useScale } from '../context/ScaleContext.js';

const axisStyles = css`
const AxisGroup = styled.g`
user-select: none;
path,
Expand All @@ -19,7 +18,7 @@ const axisStyles = css`
}
`;

const gridStyles = css`
const GridGroup = styled.g`
user-select: none;
line {
Expand Down Expand Up @@ -81,21 +80,19 @@ function XAxis(props: XAxisProps) {
return (
<>
{show && (
<g
<AxisGroup
className="x"
css={axisStyles}
transform={`translate(0,${height - margin.bottom})`}
ref={refAxis}
>
<text fill="#000" x={width - 10} y="30" dy="0.70em" textAnchor="end">
{label}
</text>
</g>
</AxisGroup>
)}
{showGrid && (
<g
<GridGroup
data-no-export="true"
css={gridStyles}
className="grid"
ref={refGrid}
transform={`translate(0,${height - margin.bottom})`}
Expand Down
10 changes: 4 additions & 6 deletions src/component/1d/YAxis.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import * as d3 from 'd3';
import { useEffect, useRef } from 'react';

import { useChartData } from '../context/ChartContext.js';
import { useScale } from '../context/ScaleContext.js';

const axisStyles = css`
const AxisGroup = styled.g`
user-select: none;
path,
Expand Down Expand Up @@ -47,9 +46,8 @@ function YAxis(props: YAxisProps) {
return (
<>
{show && (
<g
<AxisGroup
className="y"
css={axisStyles}
transform={`translate(${width - 50})`}
ref={refAxis}
>
Expand All @@ -63,7 +61,7 @@ function YAxis(props: YAxisProps) {
>
{label}
</text>
</g>
</AxisGroup>
)}
</>
);
Expand Down
36 changes: 8 additions & 28 deletions src/component/1d/integral/IntegralResizable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import type { Integral } from 'nmr-processing';

import { useChartData } from '../../context/ChartContext.js';
Expand All @@ -11,21 +10,13 @@ import { useResizerStatus } from '../../hooks/useResizerStatus.js';

import { IntegralIndicator } from './IntegralIndicator.js';

const stylesOnHover = css`
.highlight {
fill: transparent;
const Group = styled.g<{ isActive: boolean }>`
rect {
fill: ${(props) => (props.isActive ? '#ff6f0057' : 'transparent')};
}
.target {
visibility: hidden;
}
`;

const stylesHighlighted = css`
fill: #ff6f0057;
.target {
visibility: visible;
visibility: ${(props) => (props.isActive ? 'visible' : 'hidden')};
}
`;

Expand Down Expand Up @@ -79,25 +70,14 @@ function IntegralResizable({
const width = x2 - x1;

return (
<g
css={
highlight.isActive || isActive
? stylesHighlighted
: stylesOnHover
}
>
<rect
width={width}
height={bottom}
className="highlight"
data-no-export="true"
/>
<Group isActive={highlight.isActive || isActive}>
<rect width={width} height={bottom} data-no-export="true" />
<IntegralIndicator
value={integral}
format={integralFormat}
width={width}
/>
</g>
</Group>
);
}}
</ResizerWithScale>
Expand Down
39 changes: 18 additions & 21 deletions src/component/elements/ActionsButtonsPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
/** @jsxImportSource @emotion/react */
import type { PopoverProps } from '@blueprintjs/core';
import { Popover } from '@blueprintjs/core';
import type { Interpolation, Theme } from '@emotion/react';
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import type { CSSProperties } from 'react';
import type { ButtonProps } from 'react-science/ui';
import { Button } from 'react-science/ui';

const Container = styled.div<Pick<CSSProperties, 'flexDirection' | 'gap'>>`
display: flex;
flex-direction: ${(props) => props.flexDirection};
gap: ${(props) => props.gap};
button,
a[role='button'] {
border-radius: 50%;
min-width: 16px;
min-height: 16px;
font-size: 10px;
padding: 5px;
}
`;

export interface ActionsButtonsPopoverProps
extends Omit<PopoverProps, 'interactionKind' | 'content'> {
buttons: Array<
Expand Down Expand Up @@ -42,24 +56,7 @@ export function ActionsButtonsPopover(props: ActionsButtonsPopoverProps) {
interactionKind="hover"
enforceFocus={false}
content={
<div
style={{
display: 'flex',
flexDirection: direction,
gap: space,
...contentStyle,
}}
css={css`
button,
a[role='button'] {
border-radius: 50%;
min-width: 16px;
min-height: 16px;
font-size: 10px;
padding: 5px;
}
`}
>
<Container style={contentStyle} flexDirection={direction} gap={space}>
{buttons
.filter((button) => button?.visible !== false)
.map(({ title, visible, ...otherProps }, index) => (
Expand All @@ -69,7 +66,7 @@ export function ActionsButtonsPopover(props: ActionsButtonsPopoverProps) {
{...otherProps}
/>
))}
</div>
</Container>
}
{...otherProps}
>
Expand Down
1 change: 0 additions & 1 deletion src/component/elements/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/** @jsxImportSource @emotion/react */
import type { ButtonProps } from '@blueprintjs/core';
import { Button, Dialog, DialogBody, DialogFooter } from '@blueprintjs/core';
import styled from '@emotion/styled';
Expand Down
10 changes: 10 additions & 0 deletions src/component/elements/DialogBody.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { DialogBody as BaseDialogBody } from '@blueprintjs/core';
import styled from '@emotion/styled';
import type { CSSProperties } from 'react';

export const DialogBody = styled(BaseDialogBody)<
Pick<CSSProperties, 'padding' | 'backgroundColor'>
>`
padding: ${({ padding = '15px' }) => padding};
background-color: ${({ backgroundColor = 'white' }) => backgroundColor};
`;
11 changes: 6 additions & 5 deletions src/component/elements/Label.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import type { CSSProperties, LabelHTMLAttributes, ReactNode } from 'react';

import Button from './Button.js';

const ShortTitle = styled.span`
display: none;
`;

export interface LabelStyle {
label?: CSSProperties;
wrapper?: CSSProperties;
Expand Down Expand Up @@ -53,9 +56,7 @@ export default function Label(props: LabelProps) {
<span className={shortTitle ? 'large-label' : ''}>{title}</span>
)}
{shortTitle && (
<span className="small-label" css={css({ display: 'none' })}>
{shortTitle}
</span>
<ShortTitle className="small-label">{shortTitle}</ShortTitle>
)}
{description && (
<Button.Info
Expand Down
Loading

0 comments on commit fb89d97

Please sign in to comment.