]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19900 new Numbered List component
authorJeremy Davis <jeremy.davis@sonarsource.com>
Wed, 12 Jul 2023 08:45:25 +0000 (10:45 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 12 Jul 2023 20:03:30 +0000 (20:03 +0000)
server/sonar-web/design-system/src/components/NumberedList.tsx [new file with mode: 0644]
server/sonar-web/design-system/src/components/NumberedListItem.tsx [new file with mode: 0644]
server/sonar-web/design-system/src/components/__tests__/NumberedList-test.tsx [new file with mode: 0644]
server/sonar-web/design-system/src/components/index.ts
server/sonar-web/design-system/src/theme/light.ts

diff --git a/server/sonar-web/design-system/src/components/NumberedList.tsx b/server/sonar-web/design-system/src/components/NumberedList.tsx
new file mode 100644 (file)
index 0000000..a6934df
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+import styled from '@emotion/styled';
+import tw from 'twin.macro';
+
+export const NumberedList = styled.ol`
+  list-style: none;
+  counter-reset: li;
+  ${tw`sw-mt-4`}
+  ${tw`sw-pl-0`}
+
+  li:last-child {
+    ${tw`sw-mb-0`}
+  }
+`;
+
+NumberedList.displayName = 'NumberedList';
diff --git a/server/sonar-web/design-system/src/components/NumberedListItem.tsx b/server/sonar-web/design-system/src/components/NumberedListItem.tsx
new file mode 100644 (file)
index 0000000..0951502
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+import styled from '@emotion/styled';
+import tw from 'twin.macro';
+import { themeColor } from '../helpers/theme';
+
+export const NumberedListItem = styled.li`
+  counter-increment: li;
+  ${tw`sw-mb-4`}
+  ${tw`sw-ml-1`}
+
+  &::before {
+    width: 19px;
+    height: 19px;
+    color: ${themeColor('numberedListText')};
+    background-color: ${themeColor('numberedList')};
+    border-radius: 20px;
+    content: counter(li);
+
+    ${tw`sw-body-sm-highlight`}
+    ${tw`sw-p-1`}
+    ${tw`sw-mr-3`}
+    ${tw`sw-inline-block`}
+    ${tw`sw-text-center`}
+  }
+`;
+
+NumberedListItem.displayName = 'NumberedListItem';
diff --git a/server/sonar-web/design-system/src/components/__tests__/NumberedList-test.tsx b/server/sonar-web/design-system/src/components/__tests__/NumberedList-test.tsx
new file mode 100644 (file)
index 0000000..15f193d
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import { screen } from '@testing-library/react';
+import { render } from '../../helpers/testUtils';
+import { NumberedList } from '../NumberedList';
+import { NumberedListItem } from '../NumberedListItem';
+
+it('renders correctly', () => {
+  render(
+    <NumberedList>
+      <NumberedListItem>First item</NumberedListItem>
+      <NumberedListItem>Second item</NumberedListItem>
+    </NumberedList>
+  );
+  expect(screen.getAllByRole('listitem')).toHaveLength(2);
+});
index ed1ce6e965626c0a95a55334c42f2fb2b6a47d12..2168d14630548ad696d7c923a0fc7a4d2844e6a0 100644 (file)
@@ -59,6 +59,8 @@ export * from './MainMenuItem';
 export * from './MetricsRatingBadge';
 export * from './NavBarTabs';
 export * from './NewCodeLegend';
+export * from './NumberedList';
+export * from './NumberedListItem';
 export * from './OutsideClickHandler';
 export { QualityGateIndicator } from './QualityGateIndicator';
 export * from './SearchHighlighter';
index b666a011c45482d42a7bcf696d7e14312e029713..c2d3738838d68e07608dd4bf6e3ea55ceee92b59 100644 (file)
@@ -341,6 +341,7 @@ export const lightTheme = {
 
     // numbered list
     numberedList: COLORS.indigo[50],
+    numberedListText: COLORS.indigo[800],
 
     // unordered list
     listMarker: COLORS.blueGrey[300],