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

[LG-4657] Code improvements integration #2670

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
152 changes: 152 additions & 0 deletions .changeset/chatty-ears-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
'@leafygreen-ui/code': major
---

## What's new?

### `panel`

Adds a new slot prop, `panel`, that accepts the new `<Panel/>` sub-component. This will render the top panel with a language switcher, custom action buttons, and copy button. If no props are passed to the panel sub-component, the panel will render with only the copy button.

**_Note: `copyButtonAppearance` cannot be used with `panel`. Either use `copyButtonAppearance` or `panel`, not both._**

e.g.

```js
panel={
<Panel
onChange={() => {}}
languageOptions={[]}
showCustomActionButtons
customActionButtons={[]}
title="Title"
/>
}
```
or
```js
panel={<Panel/>}
```

### `copyButtonAppearance`
Adds a new prop, `copyButtonAppearance`. This prop determines the appearance of the copy button if the `panel` prop is not defined. If `panel` is defined, this prop will be ignored.

If `hover`, the copy button will only appear when the user hovers over the code block. On mobile devices, the copy button will always be visible.

If `persist`, the copy button will always be visible.

If `none`, the copy button will not be rendered.

**_Note: 'panel' cannot be used with `copyButtonAppearance`. Either use `copyButtonAppearance` or `panel`, not both._**

e.g.

```js
<Code
language="javascript"
copyButtonAppearance="hover"
>
{snippet}
</Code>
```

### `isLoading`
Adds a new prop, `isLoading`. This prop determines whether or not the loading skeleton will be rendered in place of the code block. If `true`, the language switcher and copy button will be disabled in the top panel.

e.g.

```js
<Code
language="javascript"
isLoading
>
{snippet}
</Code>
```


### `chromeTitle`

`<Panel/>` accepts the [deprecated `Code` props](https://github.com/mongodb/leafygreen-ui/tree/main/packages/code#deprecated) listed below, with one key difference: the `chromeTitle` prop has been replaced by `title`. Instead of rendering inside the window chrome bar, the `title` now appears within the top panel, as the window chrome bar has been removed.

e.g.

**Before**:
```js
<Code chromeTitle="title">{snippet}</Code>
```

**After**:
```js
<Code
panel={<Panel title="Title" />}
>
{snippet}
</Code>
```

### Test Harnesses
Exports `getTestUtils`, a util to reliably interact with LG `Code` in a product test suite. For more details, check out the [README](https://github.com/mongodb/leafygreen-ui/tree/main/packages/code#test-harnesses) [LG-4799](https://jira.mongodb.org/browse/LG-4799)

Exports `getLgIds`, a util to instantiate an object of `data-lgid` values for a given LG `Code` component instance.

### `baseFontSize`
Adds `baseFontSize` prop, which allows you to override the `LeafyGreenProvider` value.

## What's changed?

The `className` prop is no longer applied to the `<pre>` tag. Instead it is applied to the parent `<div>` wrapper.


## Deprecated

The following props have been marked as `deprecated`:
- `customActionButtons`
- `showCustomActionButtons`
- `chromeTitle`
- `languageOptions`
- `onChange`
- `copyable`

Moving forward these props should be passed to the new sub-component, `<Panel />`.

**Before**:
```js
<Code
language="javascript"
showLineNumbers
onCopy={() => {}}
darkMode={true}
onChange={() => {}}
languageOptions={[]}
showCustomActionButtons
customActionButtons={[]}
chromeTitle='Title'
>
{snippet}
</Code>
```

**After**:
```js
<Code
language="javascript"
showLineNumbers
onCopy={() => {}}
darkMode={true}
// NEW PANEL PROP
panel={
<Panel
onChange={() => {}}
languageOptions={[]}
showCustomActionButtons
customActionButtons={[]}
title="Title"
/>
}
>
{snippet}
</Code>
```

Check out the [README](https://github.com/mongodb/leafygreen-ui/tree/main/packages/code#panel) for information on the `<Panel>` sub-component.
5 changes: 5 additions & 0 deletions .changeset/cool-bottles-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/lib': minor
---

Adds `getMobileMediaQuery` helper. This helper targets a specified screen size with no pointer, or a coarse pointer and no hover capability
5 changes: 5 additions & 0 deletions .changeset/soft-experts-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/select': minor
---

Exports `type GetTestUtilsReturnType`.
5 changes: 5 additions & 0 deletions .changeset/tame-timers-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/button': minor
---

Exports `type GetTestUtilsReturnType`.
5 changes: 5 additions & 0 deletions .changeset/wild-insects-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/select': patch
---

Internally updates `MobileMediaQuery` to use `getMobileMediaQuery` from `@leafygreen-ui/li`
2 changes: 1 addition & 1 deletion packages/button/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { Button as default } from './Button';
export type { BaseButtonProps, ButtonProps } from './types';
export { FontSize, Size, Variant } from './types';
export { getTestUtils } from './utils';
export { getTestUtils, type GetTestUtilsReturnType } from './utils';
1 change: 1 addition & 0 deletions packages/button/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { getTestUtils } from './getTestUtils';
export type { GetTestUtilsReturnType } from './getTestUtils.types';
Loading