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

fix: use semantic elements #341

Merged
merged 5 commits into from
Apr 5, 2023
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: 4 additions & 1 deletion packages/mdx/src/mini-editor/code-browser.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "../utils/mixins.scss";

.ch-code-browser {
display: flex;
height: 100%;
Expand Down Expand Up @@ -45,9 +47,10 @@
}

.ch-code-browser-button {
@include button-reset;

width: 1.5em;
height: 1.5em;
cursor: pointer;
min-width: 1.5em;
min-height: 1.5em;
position: absolute;
Expand Down
5 changes: 4 additions & 1 deletion packages/mdx/src/mini-editor/dialog.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "../utils/mixins.scss";

.ch-no-scroll {
overflow: hidden;
}
Expand All @@ -15,10 +17,11 @@
}

.ch-expand-close {
@include button-reset;

position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
color: white;
width: 26px;
height: 26px;
Expand Down
62 changes: 34 additions & 28 deletions packages/mdx/src/mini-editor/expand-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,44 +94,50 @@ function ExpandIcon({
className?: string
}) {
return (
<svg
<button
type="button"
title="Expand"
style={style}
onClick={onClick}
className={className}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
role="button"
>
<title>Expand</title>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"
/>
</svg>
<svg
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"
/>
</svg>
</button>
)
}
function CloseButton({ onClick }: { onClick: () => void }) {
return (
<svg
<button
onClick={onClick}
className="ch-expand-close"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
role="button"
type="button"
title="Close"
>
<title>Close</title>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
<svg
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
)
}
4 changes: 3 additions & 1 deletion packages/mdx/src/mini-editor/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@import "../smooth-code/index.scss";
@import "./dialog.scss";
@import "./code-browser.scss";
@import "../utils/mixins.scss";

/** tabs */

Expand Down Expand Up @@ -96,9 +97,10 @@
}

.ch-editor-button {
@include button-reset;

width: 1.5em;
height: 1.5em;
cursor: pointer;
min-width: 1.5em;
min-height: 1.5em;
margin-right: 0.8em;
Expand Down
51 changes: 27 additions & 24 deletions packages/mdx/src/smooth-code/copy-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export function CopyButton({
const [copied, setCopied] = React.useState(false)

return (
<svg
<button
type="button"
title="Copy code"
className={className}
style={style}
onClick={() => {
copyToClipboard(content)
Expand All @@ -21,30 +24,30 @@ export function CopyButton({
setCopied(false)
}, 1200)
}}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
className={className}
>
<title>Copy</title>

{copied ? (
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M5 13l4 4L19 7"
/>
) : (
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.6px"
d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
/>
)}
</svg>
<svg
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
{copied ? (
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M5 13l4 4L19 7"
/>
) : (
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.6px"
d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
/>
)}
</svg>
</button>
)
}

Expand Down
5 changes: 4 additions & 1 deletion packages/mdx/src/smooth-code/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "../utils/mixins.scss";

.ch-code-line-number {
user-select: none;
text-align: right;
Expand Down Expand Up @@ -28,10 +30,11 @@
}

.ch-code-button {
@include button-reset;

position: absolute;
top: 10px;
right: 10px;
width: 1.1em;
height: 1.1em;
cursor: pointer;
}
11 changes: 11 additions & 0 deletions packages/mdx/src/utils/mixins.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@mixin button-reset {
-webkit-appearance: button;
background-color: transparent;
background-image: none;
cursor: pointer;
color: inherit;
margin: 0;
padding: 0;
border: none;
font-size: inherit;
}